gnu-misc-discuss
[Top][All Lists]
Advanced

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

Re: Python question


From: Brandon Invergo
Subject: Re: Python question
Date: Thu, 10 Apr 2014 09:14:22 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

> How, in Python, can I execute a string as a shell command?

You should use the 'call' function of the 'subprocess' module.  You can
either pass it a string with the full command or a list of strings
comprising the command (like execv in libc).  You must pass the
'shell=True' option if you are passing the full string; otherwise it can
be omitted.

    import subprocess
    subprocess.call("ls -l /home/rms", shell=True)
    subprocess.call(["ls", "-l", "/home/rms"])

-brandon

-- 
Brandon Invergo
http://brandon.invergo.net

Attachment: pgpcu8R44NVNq.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]