Passing parameters for a C program in Linux.

Miles Kaufmann milesck at umich.edu
Tue Jun 30 11:44:50 EDT 2009


On Jun 30, 2009, at 6:46 AM, venutaurus539 at gmail.com wrote:

>       I have to write an automted script which will test my c
> program. That program when run will ask for the commands.

Keep in mind that, if your test script checks the program's output  
before giving it input, you can run into problems with buffering.  The  
standard C library uses line-based buffering when a program is using a  
terminal for output, but when it's outputting to a pipe it uses block  
buffering.  This can be a problem when running a process using  
subprocess--your program will buffer the prompt, and your test script  
won't see it, so the test will deadlock.  The problem can also exist  
in the opposite direction.

Possible solutions:
- Explicitly set both your test script and your program to have line- 
buffered output.
- Add a flush statement whenever you finish writing output and expect  
input.
- Use pexpect, which uses a pseudo-tty and will make C stdio default  
to line buffering.
- Use pdpi's solution, which, since it doesn't wait for a prompt  
before supplying input, doesn't have this issue.



More information about the Python-list mailing list