spawning unix command processes which run in parallel and simultaneously

Bufu spam at sightreader.com
Sun Jun 10 07:47:54 EDT 2001


Yes, os.popen and friends are what you want.

I recommend trying stuff in the interpreter; it's more fun that reading
documentation, and usually more instructive, and more accurate.

The documentation seems to have the wrong argument order for popen2, popen3,
and popen4, where the optional bufsize and more arguments are swapped
(should read "popen2 (cmd[, mode [, bufsize]])").

The documentation is in the os module under "6.1.2 File Object Creation"
presumably because it creates file like objects.  I would have expected it
to be in "6.1.5 Process Management", or at least a cross-reference there.

By the way, it seems to act strangely in PythonWin:

>>> f =os.popen(r'C:\junk\test.exe')
Traceback (innermost last):
  File "<interactive input>", line 1, in ?
WindowsError: [Errno 2] The system cannot find the file specified

The same happens for any command line string, but it works fine in the
console version of python.

----- Original Message -----
From: "Alan Tsang" <atsang at hk.linkage.net>
Newsgroups: comp.lang.python
To: <python-list at python.org>
Sent: Sunday, June 10, 2001 3:23 AM
Subject: spawning unix command processes which run in parallel and
simultaneously


>
> HI, I am learning to code with Python and I encounter a technical problem.
>
> I want to spawn a few unix command processes from a python script so that
I
> can get the output from the unix command processes and use them in python.
>
> But I don't want to wait for the completion of one process at a time and
> then start another.  I want the python script to start the processes
> simultaneously and monitor whether anyone of them have finished and if so,
> get the output from the finished one.
>
> It seems to me that the os and popen2 module is useful in this respect but
> I am not sure how to do it.
>
> Is it possible to do it in python?  would be grateful if anyone can give
me
> a reference to any documentation.
>
> Thanks
>
> --
> http://mail.python.org/mailman/listinfo/python-list





More information about the Python-list mailing list