newbie system() question

Donn Cave donn at drizzle.com
Sun Jun 9 12:56:26 EDT 2002


Quoth "Dan Larsen" <dl at bestpriceeu.com>:
| Im trying to run a script on a FreeBSD 4.0 system.
| It works as long as I start it like "python myprogram.py", but as soon as I
| run it in the background, it is stopped, and I have to make it run in the
| foreground to continue i.e. "fg %1"... I know it is a call to a system(""),
| that makes it stop... The system() call runs a program that outputs some
| text... how do I stop it doing so? It doesn't help telling it to do stuff
| like "program >& /dev/null &"... Isn't there a function, where all output
| from the command, is parsed to a variable?

Yes, there is.

Your background program stops because of a Berkeley job control
function in the tty driver (all modern UNIX implementations do the
same - as with sockets, everyone is Berkeley in this respect.)
To see exactly what happened, type "jobs" or "jobs -l", and you'll
see something like "[1] + Stopped(SIGTTOU)"  That means your background
job tried to write to the terminal driver, and got put to sleep.
Or it might say "(SIGTTIN)" instead, which means the job tried to read.
The latter is more or less inevitable, you don't want background jobs
reading input from the tty, but the former is optional:  try "stty tostop",
and see if it makes any difference.

The redirection syntax "program >& /dev/null &" won't help in system(),
because it isn't valid for the Bourne shell.  If you want to redirect
both standard and diagnostic output to /dev/null in the Bourne shell,
try "program >&2 /dev/null".

The shell notation for output to a variable is X="`program`".

	Donn Cave, donn at drizzle.com



More information about the Python-list mailing list