How to use cmd from python

Im trying to use python to run cmd.exe and thereby running commands like cd C:name..... and executing other programs from the cmd what I have so far is.

os.system("cmd.exe").
os.system("cd C:namefirstsecond").

When I try to run three other commands a new cmd window replaces the old one and the commands dont work since they need to be consecutively after each other.I already tried the above code and need help running the next three. Also can you explain what suproccess are.


See my answer to this recent question for why os.system("cd WHEREVER") does not do what you expect.

Briefly, when you run os.system('cd WHEREVER') you are creating a new command shell which has its own idea of the current directory. This change in the current directory will be entirely "forgotten" on subsequent calls to os.system() . You need to change the current directory in the parent process (the script) with os.chdir('WHEREVER') in order to retain the change for subsequent os.system() calls.

链接地址: http://www.djcxy.com/p/56498.html

上一篇: 在python cmd模块中自动完成和简单实现子命令?

下一篇: 如何从python使用cmd