How do I pass an argument to the system shell in Python and get the output back as an array or string?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
os.systemis not designed to do that;os.popenis. Both have been obsoleted by thesubprocessmodule, which should be used for writing new code. To capture the output of a shell command, you would instantiate asubprocess.Popenobject and callcommunicate()to retrieve its output.In addition to the above, the utility function
check_output, new in Python 2.7, is a plugin-replacement for shell backquotes, i.e. you pass it the command to execute and get back the output as a string: