shell script executes program, but waits for a prompt

Sorry, newbie here. I have the following shell script which basically executes the sh-n-body.i686 program a specified number of times. However, before the sh-n-body.i686 begins its calculations it prompts for input from the user. In this case the user would have press ". return" and sh-n-body.i686 will continue running. However, I just want the code to run about 100 times without having to enter . return. How can I modify the shell script so that it takes care of the prompt( . return).

#!/bin/sh
COUNTER=0
while [ $COUNTER -lt 100 ]; do
./sh-n-body.i686 56 3 32 0.02 1 -2 | grep "longest shadow"
let COUNTER=COUNTER+1
done

Thank you

echo . | ./sh-n-body.i686 56 3 32 0.02 1 -2 | grep "longest shadow"

the above code just results in a . after the sh-n-body has finished. I still get the prompt:

"Enter comment, ^D or . to end."

and still have to enter ". return" for the code to continue.

Do you have access to the source code, or perhaps even the ability to change it? Perhaps it's reading /dev/tty rather than stdin, or something similarly inconvenient.

The ./sh-n-body.i686 script is expecting the input, not the script that you showed in the example.
Somewhere in the script, there is probably a 'read' statement. Looks like this perhaps:

read value

When you enter your input, it gets stored in $value.
Only thing you have to do is manually assign your input to $value, like so:

value="your input here"

I do have the source code, but I hesitate to change it. Here is the portion that has the prompt

fputs("Enter comment, ^D or . to end.\n", stderr);
puts("Comment:");
while(fgets(_line, sizeof(_line), stdin) && _line[0] != '.')
fputs(_line, stdout);
puts("");

I don't know if it makes a difference but ./sh-n-body.i686 is a c file not a shell script.

Quote:
Originally Posted by lionatucla View Post
the above code just results in a . after the sh-n-body has finished. I still get the prompt
The ./sh-n-body.i686 script is expecting the input, not the script that you showed in the example.

Somewhere in the script, there is probably a 'read' statement. Looks like this perhaps:

Code:

read value

When you enter your input, it gets stored in $value.
Only thing you have to do is manually assign your input to $value, like so:

Code:

value="your input here"

I put the code you posted into a C file and compiled it. It works for me.

vnix$ gcc lionatucla.c
vnix$ ./a.out </dev/null
Enter comment, ^D or . to end.
Comment:

vnix$ echo . | ./a.out
Enter comment, ^D or . to end.
Comment:

I did not type anything at the prompt at any point.

Does the code mess with stdin at any earlier point (like, maybe close it)?

I'm sure you are aware of the security problems of fgets() but that discussion doesn't belong here.