python print os command output -1 1

python print os command output -1

subprocess = subprocess.Popen("echo Hello World", shell=True, stdout=subprocess.PIPE)

Here is what the above code is Doing:
1. We’re creating a subprocess.Popen object.
2. We’re passing it a string that contains the command we want to run.
3. We’re setting the shell argument to True. This tells Python to run the command as if it were a shell command.
4. We’re setting the stdout argument to subprocess.PIPE. This tells Python to send the output of the command to a pipe.
5. We’re calling the communicate() method on the subprocess.Popen object. This tells Python to wait for the command to finish running.
6. We’re printing the output of the command.

Similar Posts