gcc (GCC) 4.7.2
GNU bash, version 4.2.37
Hello,
I have the following bash script that I want to pass string parameter to my c program. I tried using pipes but failed.
The c program will need to get an input from the shell script. I am not sure to to read in an input from a shell script.
My bash script is below.
#!/usr/bash
# About on any errors
set -e
RUN_WITH_VALGRIND=""
if [ "$1" == "valgrind" ]; then
RUN_WITH_VALGRIND="valgrind"
echo "START TESTING WITH VALGRIND"
fi
$RUN_WITH_VALGRIND ./c_program
echo "Hello" | ./c_program
And my sample c program is here:
char str_input[16];
printf("Get input: ");
scanf("%s", str_input);
printf("Input [ %s ]\n", str_input);
I am trying to get the scanf to read the input from the shell script.
Many thanks for any advice,
echo "Hello" | $RUN_WITH_VALGRIND ./c_program, it’s that simple.But in your script, c_program will run twice as you re-call it after the
run_with_valgrindcall (I don’t know if its intend or not)