小编Emm*_*dev的帖子

Python 子进程调用复制文件时出错。没有文件,失败,但返回 1。为什么?

import subprocess
import os

#files
src_file = '/../copy_me_test.txt'
destination_file = 'paste_here.txt'

#make copy of file
shell_command = 'cp "%s" "%s"' % (src_file, destination_file)
successful = subprocess.call(shell_command, shell = True)
print(successful)
Run Code Online (Sandbox Code Playgroud)

所以我将文件从一个目录复制到另一个目录。当我运行 subprocess.call() 方法时,它返回 1。除了没有任何反应,我在终端上收到以下消息。

cp: /Users/my_name/Desktop/python/copy_files/copy_me_test.txt: No such file or directory
1
Run Code Online (Sandbox Code Playgroud)

这里发生了什么?因为它无法复制文件,所以不应该返回 0 吗?我已经做了解决办法,但我想知道是否有人知道为什么会发生这种情况?任何信息或链接将不胜感激。

python subprocess python-3.x python-3.6

5
推荐指数
1
解决办法
1198
查看次数

标签 统计

python ×1

python-3.6 ×1

python-3.x ×1

subprocess ×1