Mar-13-2017, 01:40 PM
Hello All,
I'd like to run a windows cmd and get the result in a variable..it works well for a command but not for another...
Here is :
Command "whoami" > Works !!
thanks for all :-)
I'd like to run a windows cmd and get the result in a variable..it works well for a command but not for another...

Here is :
Command "whoami" > Works !!

import subprocess
p1=subprocess.Popen(["whoami"],stdout=subprocess.PIPE)
print(p1.communicate()[0])
Output:b'asus\\joe\r\n'
Command "path" > Doesn't Works !! 
import subprocess
p1=subprocess.Popen(["path"],stdout=subprocess.PIPE)
print(p1.communicate()[0])
Output:Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Joe\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 676, in __init__
restore_signals, start_new_session)
File "C:\Users\Joe\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 955, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] [color=#545454][size=small][font=arial, sans-serif]The system cannot find the file specified[/font][/size][/color]
The command "path" is just an example, in fact I'd like to execute a more complex command but it causes python to the same error...thanks for all :-)