0
how can use cmd in py file?
###
2 ответов
+ 1
I use this kind of code instead:
import subprocess
try:
popen = subprocess("echo Hello world!", shell=True, stdout=subprocess.PIPE)
ret = popen.wait()
except:
sys.exit(1)
out = popen.stdout.read()
print("----- ret: "+str(ret))
print("\n\n----- out:\n"+out)
sys.exit(0)
ret is an integer with the return value of the command, while you can read the standard output ( stdout ) result as string ( then you can use it for retrieving some information ).
I don't know if it work too on ms windows.
But by using command line, you break the platform independance from your code ( and mine is on linux ^^ )...
0
i use import os
os.system(cmd)
but dont work!