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 吗?我已经做了解决办法,但我想知道是否有人知道为什么会发生这种情况?任何信息或链接将不胜感激。