[英]Python return code for os.system() and subprocess.call() command
I am running python on windows server. 我在Windows服务器上运行python。
I want the return code for os.system , so that i can check whether robocopy was successful or not. 我想要os.system的返回码,以便可以检查robocopy是否成功。
a=os.system('robocopy \\\\aucb-net-01\\d$ \\\\nasc01\\rem\\aucb-net-01 /E /MIR')
will "a"
have any value ? "a"
有什么价值吗? can i print it ? 我可以打印吗? like this print ("a",a)
像这样的印刷品("a",a)
and then I can decide whether the robocopy was successful or not. 然后我可以决定自动复制是否成功。
Also how can I run above robocopy with subprocess.call() command? 另外,如何使用subprocess.call()命令在robocopy上运行? And also get the return code. 并获得返回码。
thanks everyone for reading my post. 感谢大家阅读我的文章。
using os.system 使用os.system
import os
cmd = os.system('robocopy \\\\aucb-net-01\\d$ \\\\nasc01\\rem\\aucb-net-01 /E /MIR')
exit_code = os.WEXITSTATUS(cmd)
using subprocess 使用子过程
import subprocess
exit_code = subprocess.call('robocopy \\\\aucb-net-01\\d$ \\\\nasc01\\rem\\aucb-net-01 /E /MIR', shell=True)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.