简体   繁体   中英

Python return code for os.system() and subprocess.call() command

I am running python on windows server.

I want the return code for os.system , so that i can check whether robocopy was successful or not.

a=os.system('robocopy \\\\aucb-net-01\\d$ \\\\nasc01\\rem\\aucb-net-01 /E /MIR')

will "a" have any value ? can i print it ? like this print ("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? And also get the return code.

thanks everyone for reading my post.

using 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM