Popen bash command eval check for command that read from stdin?
Hi group,
I'm writing a C program that calls popen to eval a command string. One problem is if the command wants to read from stdin, it hangs! For example 'popen( "eval cat", "r" )' will hang. Is there a way I can filter such programs? Thanks for your time. |
Well, umm, Mr. Umunhum :-)
From only what you've provided, I'm not sure what you're overall goal or approach is, beyond not wanting to hang will trying to read from a FILE * you've popen'd. But the following doesn't hang for me. poeb.c: Code:
# include <stdio.h> Code:
Congratulations! You have been successful!! Code:
Congratulations! You have been successful!! running the cat command with no file specified to cat will cause the cat command to read from "stdin"/the-tty which will never end unless stdin is terminated in some way, or the process is killed. I generally try a command manually before I run it from a program. I hope this helps. |
Quote:
I'm writing a user interface and have little control over what the user does. Quote:
|
Quote:
Quote:
But if somehow you really can't, then perhaps some sort of "Sandbox" can be used to prevent problems. Especially if they have unrestricted access to a shell where they could run commands that could start other commands, and even start multiple commands. Quote:
If on a computer which is more or less just sitting around not doing much, a User wants to run a simple command, perhaps to do a quick calculation: Code:
dc -e '135 29 * p' |
Well I have concluded there is no way to use Popen for this. I have rewritten my program so many times with varying levels of success. The latest version is at:http://http://mt-umunhum-wireless.ne...curses/Popen.c. But is has one last bug, after timeing out the command, it tries to pclose the sub-command and hangs on a waitpid(). Requiring yet another 'Enter'.
My solution is to use Pipe() instead of Popen(). Thanks for your time and posts. |
All times are GMT -5. The time now is 12:44 AM. |