我有如下命令
subprocess.check_call(["C:\\Program Files\\operation.exe", "execute", "-af", "createrecord.xml", " -stuName", student,"-gender" ,gender], shell=True)
当我手动运行此命令时,它工作正常。我相信 subprocess.check_call() 没有正确解析命令(可能是我的错误)。如何查看subprocess.check_call()的输出。
我希望看到由 subprocess.check_call() 调用的带参数的实际命令
注意 - 我不想看到命令执行的返回值。我只是想看看命令是如何被 subprocess.check_call() 格式化的
请您参考如下方法:
您应该使用 subprocess 的列表形式仅包含(可能隐含)shell=False 的内容和字符串形式仅与 shell=True .
shell 只能使用命令行,然后它自己解析。没有外壳,exec*() usedm 函数以单独的方式获取命令行参数。
对于 Windows,这仅适用于特定级别,但仍然有效。
