Reputation: 13206
I am trying to robocopy media from one windows machine to another on a network using robocopy and python 3.
I have tried just about every combination I can of subprocess
and robocopy
but I am still getting errors.
Here is my most recent try:
print(subprocess.check_output(["robocopy", "\\172.21.81.23\c\media\\ \\172.21.81.10\c\media\videos\\"], shell=True))
I ma not sure if it is the backslashes, or what, but I always get the following response:
Traceback (most recent call last):
File "",line 7, in tableChange
File "C:\Program Files line 586, in check_output
raise CalledProcessError(retcode, process.args, output=output)
subprocess.CalledProcessError: Command '['robocopy', '\\172.21.81.23\\c\\media\\cmsupload\\ \\172.21.81.10\\c\\media\\videos\\']' returned non-zero exit status 16
Does anyone have any suggestions?
Upvotes: 0
Views: 1305
Reputation: 155536
You either don't split the arguments (and use shell=True
) or split them completely (and don't use shell=True
), you can't split only the command from the arguments. Also, for Windows paths, you want to use raw strings to avoid problems with ASCII escapes being processed in paths by accident (prefixed with an r
, e.g. r'\\foo\bar'
, and don't include the trailing slash or things get weird) so you might do:
print(subprocess.check_output(['robocopy', r'\\172.21.81.23\c\media', r'\\172.21.81.10\c\media\videos']))
Upvotes: 1