osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to execute shell command in Python program?


Madhavan Bomidi wrote:
> import subprocess
> subprocess.call(['./opac'],shell=True)

subprocess.call(['./opac', "my-input.inp"], shell=True)

The array takes command with a list of arguments. This
way you don't need to do space escaping and other
Jujitsu gimmicks.

If you want to feed the command from stdin, this becomes a bit
more complicated as you need to start a subprocess and use
PIPE to feed it.

Cheers,
Chris Narkiewicz

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20190720/9156b259/attachment.sig>