The main goal for us is how to use this programming language in everyday life with different tasks.
Today I will come up with examples to cover this goal and show you how to use the subprocess python module.
- using the PowerShell with python :
>>> import subprocess
>>> process=subprocess.Popen(["powershell","Get-Childitem C:\\Windows\\*.log"],stdout=subprocess.PIPE);
>>> result=process.communicate()[0]
>>> print result
>>> print subprocess.check_output("hostname")
>>> print subprocess.check_output("ping localhost", shell=True)
>>> cmd = 'dir *'
>>> supcmd = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
>>> print supcmd.communicate()[0]
>>> import sys
>>> import subprocess
>>> pid = subprocess.Popen([sys.executable, "calc.py"])