I try to wrap cmd.exe under windows with the following program but it doesn't work , it seems to wait for something and doesn't display anything. Any idea what is wrong here ?
import subprocess
process = subprocess.Popen('cmd.exe', shell=False, stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=None)
process.stdin.write("dir\r\n")
output = process.stdout.readlines()
print output
Usually when trying to call command prompt with an actual command, it is simpler to just call it with the "/k" parameter rather than passing commands in via stdin. That is, just call "cmd.exe /k dir". For example,
from os import *
a = popen("cmd /k dir")
print (a.read())
The code below does the same thing, though lacks a string for you to manipulate, since it pipes to output directly:
from subprocess import *
Popen("cmd /k dir")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With