13,420
edits
Changes
→PART 2 - Running System Commands with Subprocess
== PART 2 - Running System Commands with Subprocess ==
:The remainder of this lab will allow you to run operating system commands via your Python script. Although there are different ways in which to issue operating system commands, you will learn how to issue them within a Python script to run in a secure manner regardless of the type of operating system platform (eg Linux, Windows, MacOSX).
'''Perform the Following Steps:'''
:#Issue the following in ipython:<source>
system(ipconfig)
</source>You should notice an error message: ''''ipconfig command not found''''. That error occurs since that is an MS Windows command, and our current platform is Linux. <br><br>It is not usually a good idea to run system commands in Python, this makes your Python code less portable and makes it require a specific operating system or a system that has those commands available. Also, allowing python to execute commands on the operating system can be a '''security problem'''. For these reasons you should only use '''sub-process''' and '''system commands''' as a last resort and stick to Python code only.
<source>
import subprocess