spawn* or exec* and fork, what should I use and how ?

Binu K S binux.lists at gmail.com
Thu Dec 16 04:19:19 CET 2004


exec calls will replace the script process with the new process.

>From the execv documentation:
"These functions all execute a new program, replacing the current
process; they do not return. On Unix, the new executable is loaded
into the current process, and will have the same process ID as the
caller. Errors will be reported as OSError exceptions."

As Peter suggested, use the subprocess module in Python 2.4.

On Thu, 16 Dec 2004 03:00:45 GMT, Lingyun Yang <jing.cheng at insightbb.com> wrote:
> Hi,
> 
>    I want to use python as a "shell like" program,
> and execute an external program in it( such as mv, cp, tar, gnuplot)
> I tried:
> 
> os.execv("/bin/bash",("/usr/bin/gnuplot",'-c "gnuplot < plot.tmp"'))
> 
> since it's in a for-loop, it should be executed many times, but
> It exits after the first time running.
> 
> so I have to use spawn* like this:
> 
> os.spawnlp(os.P_WAIT, 'gnuplot', 'gnuplot', 'plot.tmp')
> 
> It works very well.
> 
> My question is,
> 
> 1. why my exec(..) command doesn't work?
> 2. exec* must be with fork ?
> 3. In what situation, we choose one over another ?
> 
> Thank you!
> 
> regards,
> Lingyun
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list