LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Executing a C program from a script (https://www.linuxquestions.org/questions/linux-newbie-8/executing-a-c-program-from-a-script-4175504754/)

raetters 05-12-2014 03:32 PM

Executing a C program from a script
 
I currently execute a C program (example: /bin/cprogram) from a command prompt including passing a 600 character string within double quotes, and an output file name (example: /usr/outputfile).

Example:

$ /bin/cprogram "very long string with spaces, special characters, but no double quotes, etc etc" /usr/outputfile

Question: How would I write a shell script to receive that 600 character string and the output file name as input variables and then execute that same C program?

jpollard 05-12-2014 03:41 PM

I would suggest changing the cprogram to read from stdin.

That way the "600 character string" could be from a file, or a pipe...

Much more flexible.

But a shell script has exactly the same format as the command.

raetters 05-12-2014 03:51 PM

This is what I've tried without success:

#!/bin/sh
read input
read filename

/bin/cprogram $input $filename

I include the double quotes on my input. Would that be lost somewhere?

suicidaleggroll 05-12-2014 04:03 PM

Yes, that would be lost where you use $input, put quotes around that
Code:

/bin/cprogram "$input" "$filename"


All times are GMT -5. The time now is 01:12 AM.