I tried something like this, but with no effect:
command = "cmd.exe" proc = subprocess.Popen(command, stdin = subprocess.PIPE, stdout = subprocess.PIPE) proc.stdin.write("dir c:\\")
One way to fix the error would be to launch Python from the Command Prompt by passing in the full path to the executable file each time you wanted to run Python. In other words, instead of typing Python you would type something like C:\Users\me\path\to\python.exe .
The naive approach to run a shell command is by using os. system(): Let's first create a new Python file called shell_cmd.py or any name of your choice. Second, in the Python file, import the os module, which contains the system function that executes shell commands.
Open Command Prompt and type “python” and hit enter. You will see a python version and now you can run your program there.
how about simply:
import os os.system('dir c:\\')
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