2
I am unable to execute (or get the result) commands executed in Windows by Python.
I picked up some code examples I saw on various websites and responses in the OS, but none worked well for me.
import subprocess
# Exception: [WinError 2] The system cannot find the file specified
stdout = subprocess.check_call(['dir'])
proc = subprocess.Popen('cmd.exe', stdin = subprocess.PIPE, stdout = subprocess.PIPE, shell = True, bufsize = 1)
stdout, stderr = proc.communicate('dir c:\\'.encode())
# Retorna sempre a mesma coisa
print(stdout)
The only feedback I get from the above print is always this:
b'Microsoft Windows [Version 10.0.10586] r n(c) 2015 Microsoft Corporation. All Rights reserved. r n r nc: Users Daniel>More? '
I have tried running as an administrator. I have tried on another machine. I have tried several different commands, dir
is just an example. I have tried changing the parameters of Popen
.
Note: The .encode()
I put in the argument of communicate()
was on my own (also tried with b''
). From what I researched, Python recently changed the data entry pattern from several native string functions to bytes, although all the examples I thought of this method were using string.