subprocess.CalledProcessError 在 Windows 7 上从 Python 3 运行 robocopy 时 [英] subprocess.CalledProcessError When running robocopy from Python 3 on Windows 7

查看:47
本文介绍了subprocess.CalledProcessError 在 Windows 7 上从 Python 3 运行 robocopy 时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 robocopy 和 python 3 将媒体从一台 Windows 机器复制到网络上的另一台机器.

I am trying to robocopy media from one windows machine to another on a network using robocopy and python 3.

我已经尝试了 subprocessrobocopy 的几乎所有组合,但我仍然遇到错误.

I have tried just about every combination I can of subprocess and robocopy but I am still getting errors.

这是我最近的尝试:

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

大家有什么建议吗?

推荐答案

要么不拆分参数(并使用 shell=True),要么完全拆分它们(不要使用 shell=True),你不能只从参数中分离命令.此外,对于 Windows 路径,您希望使用原始字符串来避免在路径中意外处理 ASCII 转义的问题(以 r 为前缀,例如 r'\\foo\bar',并且不要包含尾部斜杠或事情变得奇怪)所以你可以这样做:

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']))

这篇关于subprocess.CalledProcessError 在 Windows 7 上从 Python 3 运行 robocopy 时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆