[英]Python/CMD command
So I am running a command in my python py file 所以我在python py文件中运行命令
myNewShell = os.system('start "%s" /d "%s" cmd /f:on /t:0A /k "W:\\Desktop\\alias.bat"' % (myShot, myWorkDir))
This opens up a shell 这打开了一个壳
How exactly would I input something into this shell directly from my python script, thus bypassing your actual cmd.exe. 我将如何直接从我的python脚本直接向此shell中输入内容,从而绕过实际的cmd.exe。 I have a bunch of DOSKEYs set up, such as maya which opens up the maya program. 我设置了一堆DOSKEY,例如maya,它打开了maya程序。 How would I add a line of code to my python script, so that it loads the shell with those aliases and inputs my command directly 我如何在我的python脚本中添加一行代码,以便它使用这些别名加载shell并直接输入我的命令
Take a look at the powerful and useful subprocess module 看看功能强大且有用的子流程模块
You can then do code like this 然后,您可以执行以下代码
import subprocess
pro = subprocess.Popen("cmd", stdout=subprocess.PIPE, stdin=subprocess.PIPE)
pro.stdin.write("mybat.bat\n")
pro.stdin.write("myother.bat\n")
pro.stdin.write("start mysillyprogram\n")
pro.stdin.flush()
pro.terminate() # kill the parent
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.