Python Forum

Full Version: System Command
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
my question here


def systemCommand(cmd):
terminalProcess = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True)
terminalOutput, stderr = terminalProcess.communicate()
What do these lines mean?
Thanks  Smile
It is a definition of a function called systemCommand.
You completely missed the Python tags where you have to put your code. No indentation at all

The function doesn't return an object
def systemCommand(cmd):
terminalProcess = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True)
terminalOutput, stderr = terminalProcess.communicate()
Apart from definition what does it do? What's the function of this def?

def systemCommand(cmd):
terminalProcess = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True)
terminalOutput, stdef systemCommand(cmd):

def systemCommand(cmd):
      terminalProcess = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True)
      terminalOutput, stdef systemCommand(cmd):
I am new to the forum , sorry for not indenting!!
It executes a shell command passed as an argument to the function.
Then gets the output but nothing else. The output is not returned and nothing else is happening except the shell command execution.

See: https://docs.python.org/3.5/library/subprocess.html