Hi,
I am using System command to execute a shell script inside the C programming..
Usage: system("sh file"); There are situations where file may be empty. During this time it gets hung. what might be the reason.
Getting struck with System command in C?
You need to re-direct output from the script to an empty target, it is probably hanging waiting for a response by trying to display information on the command screen. Better would be to also check the content of the file before executing the script, skip execution when it is empty.
Reply:When you use system function in C to spawn an application, actually it spawns the system shell (e.g. Cmd.exe) and provide the parameters to the shell for execution.
If you are using a blank or empty shell file to exectue, the system will not find any instructions there. Ideally the system should not hang, but as there is instruction, and the CS pointer is not pointing towards the right memory location, it might just go haywire and hang.
Try using spawn() function.
Reply:Why not open the file name and test for contents programmatically in C first? Then you can set a flag variable to test to bypass the script if it doesn't exist in the first place. You may want to change to a different algorithmic track to avoid some other errors in your program as well based on the test. Just a thought.
bottle palm
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment