Reputation: 62
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.
Upvotes: 1
Views: 6063
Reputation: 12265
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)
Upvotes: 2