How can I capture the return value of shutil.copy() in Python ( on DOS )?
You'll want to look at the exceptions section of the Python tutorial. In the case of shutil.copy() not finding one of the arguments, an IOError exception will be raised. You can get the message from the exception instance.
try:
shutil.copy(src, dest)
except IOError, e:
print "Unable to copy file. %s" % e
You will rarely see C-like return codes in Python, errors are signalled by exceptions instead.
The correct way of logging result is:
try:
shutil.copy(src, dest)
except EnvironmentError:
print "Error happened"
else:
print "OK"