• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

subprocess.CalledProcessError 在 Windows 7 上从 Python 3 运行 robocopy 时

用户头像
it1352
帮助1

问题说明

我正在尝试使用 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

大家有什么建议吗?

正确答案

#1

要么不拆分参数(并使用 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']))

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcckhgj
系列文章
更多 icon
同类精品
更多 icon
继续加载