Lingyun Yang 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:

Since you appear to be on a *nix system, a good choice is the proctools module in the pyNMS package.


http://sourceforge.net/projects/pynms


os.execv("/bin/bash",("/usr/bin/gnuplot",'-c "gnuplot < plot.tmp"'))

You could do this:

import proctools
proctools.spawnpipe("gnuplot plot.tmp")

You can keep your existing Python 2.3 installation, as well.

1. why my exec(..) command doesn't work?

It replaces your current process.

2. exec* must be with fork ?

in this case, yes. but proctools does that for you.

3. In what situation, we choose one over another ?

The fork-and-exec is a common pattern in *nix for spawning another process. However, there are libraries in Python that do that for you. See above.



--
\/ \/
(O O)
-- --------------------oOOo~(_)~oOOo----------------------------------------
Keith Dart <[EMAIL PROTECTED]>
public key: ID: F3D288E4 ============================================================================
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to