python-子进程windows批处理命令?
我想使用python-子进程windows批处理命令?,python,windows,batch-file,subprocess,Python,Windows,Batch File,Subprocess,我想使用子进程格式化驱动器,并弹出windows命令提示符以查看结果,但执行此操作时: subprocess.Popen(["FORMAT", drive, "/FS:FAT32", "/A:32K"], shell=True).communicate() 我得到这个错误: WindowsError: [Error 2] The system cannot find the file specified 有什么帮助吗 subprocess.Popen(["format.com", drive
子进程
格式化驱动器,并弹出windows命令提示符以查看结果,但执行此操作时:
subprocess.Popen(["FORMAT", drive, "/FS:FAT32", "/A:32K"], shell=True).communicate()
我得到这个错误:
WindowsError: [Error 2] The system cannot find the file specified
有什么帮助吗
subprocess.Popen(["format.com", drive, "/FS:FAT32", "/A:32K"], shell=True).communicate()
你可以在你的cmd shell(不是python shell…obv.)中键入
格式在哪里
。你需要shell=True
我相信哦,我的错,写这篇文章时有一个打字错误。。。已编辑…请尝试改用其真实名称(format.com)(应位于您的%Path%)我遇到了更多问题。。。如果我设置shell=true
,它会工作,但命令提示符窗口不会显示,而且FORMAT
命令执行后需要一些用户输入:/usesubprocess.Popen([“cmd”,“/K”,“FORMAT some ARGS”])。communicate()
或类似的东西……如果将完整路径放在FORMAT.com上,也可以设置shell=False