Re: Python question

2014-04-10 Thread Brandon Invergo
 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


pgpihniyntL0h.pgp
Description: PGP signature
___
gnu-misc-discuss mailing list
gnu-misc-discuss@gnu.org
https://lists.gnu.org/mailman/listinfo/gnu-misc-discuss


Re: Python question

2014-04-10 Thread Barry Margolin
In article mailman.19336.1397098937.10748.gnu-misc-disc...@gnu.org,
 Richard Stallman r...@gnu.org wrote:

 [[[ To any NSA and FBI agents reading my email: please consider]]]
 [[[ whether defending the US Constitution against all enemies, ]]]
 [[[ foreign or domestic, requires you to follow Snowden's example. ]]]
 
 How, in Python, can I execute a string as a shell command?

Use os.system()

https://docs.python.org/2/library/os.html#process-management

-- 
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
___
gnu-misc-discuss mailing list
gnu-misc-discuss@gnu.org
https://lists.gnu.org/mailman/listinfo/gnu-misc-discuss


Re: Python question

2014-04-10 Thread Florian Weimer
* Richard Stallman:

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

This is often an extremely bad idea because it results in shell
command injection vulnerabilities.  Instead of os.system(), use the
subprocess module, which keeps the argument list separate and does not
involve the shell (except when you specify the shell=True argument):

  https://docs.python.org/2/library/subprocess.html

You still need to take care of separating options and user-supplied
non-option argument.  With GNU getopt, the -- separate does the
trick.
___
gnu-misc-discuss mailing list
gnu-misc-discuss@gnu.org
https://lists.gnu.org/mailman/listinfo/gnu-misc-discuss


Re: Python question

2014-04-10 Thread Richard Stallman
[[[ To any NSA and FBI agents reading my email: please consider]]]
[[[ whether defending the US Constitution against all enemies, ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

Thanks.

-- 
Dr Richard Stallman
President, Free Software Foundation
51 Franklin St
Boston MA 02110
USA
www.fsf.org  www.gnu.org
Skype: No way! That's nonfree (freedom-denying) software.
  Use Ekiga or an ordinary phone call.


___
gnu-misc-discuss mailing list
gnu-misc-discuss@gnu.org
https://lists.gnu.org/mailman/listinfo/gnu-misc-discuss