Open main menu

CDOT Wiki β

Changes

OPS435 Python Lab 3

8 bytes added, 19:20, 2 June 2017
PART 2 - Running System Commands with Subprocess
:#To view the available non OS specific commands, issue the following:<source>
dir(subprocess)
</source>There are many available modules and attributes available as part of subprocess, we are interested in "'''Popen'''". This method subprocess.Popen() can be used to run system commands as a child process to the Python script. This below output will create a new child process, in Python we can control this through the new Python object we just created, "'''p'''". "'''p'''" now has a collection of methods(functions that are apart of a object) available, view them with '''dir()'''.<br><br>
:#To demonstrate, issue the following:<source>
p = subprocess.Popen(['date'], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
13,420
edits