1

Within a python script, I want to issue a command. In perl, I could define a command, save it as a variable (here, $cmd) then type system($cmd) and then the command is executed.

How can i do that in python?

3 Answers 3

6

You can use os.system(), but prefer subprocess instead.

Sign up to request clarification or add additional context in comments.

Comments

1

Another good choice is "commands" module: http://docs.python.org/library/commands.html.

Comments

0

you can use os.system(), or the newer subprocess module. Other possible alternatives (for older Python versions) include these. (eg os.spawn*,os.popen*,etc)

Lastly, try using Python's modules to do operating system stuff instead of calling external commands if possible, unless its a third party tool you are executing and Python doesn't have the api.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.