import subprocessimport os#filessrc_file = /../copy_me_test.txtdestination_file = paste_here.txt#make copy of fileshell_command = cp %s %s % (src_file, destination_file)successful = sub...

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)
因此,我正在将文件从一个目录复制到另一个目录.当我运行subprocess.call()方法时,它返回1.除了什么也没有发生,我在终端上收到以下消息.
cp: /Users/my_name/Desktop/python/copy_files/copy_me_test.txt: No such file or directory
1
这里发生了什么?由于它无法复制该文件,因此不应返回0.我已经做好了工作,但是我想知道是否有人知道为什么会这样吗?任何信息或链接将不胜感激.
解决方法:
返回0表示成功.不为0表示失败.返回码可以是0到4294967295之间的32位整数.请根据操作系统查看Exit status.
有时,随着Python 3文档的确认,可能会设置或接收到负的返回码.
Popen.returncode
The child return code, set by poll() and wait() (and indirectly by communicate()). A None value indicates that the process hasn’t terminated yet.
A negative value -N indicates that the child was terminated by signal N (POSIX only).
在Windows上以exit(-1)退出Python会在Windows上导致4294967295,因此Python使用无符号的32位返回码.
本文标题为:错误Python子进程调用复制文件.没有文件,失败,但是返回1.为什么?


基础教程推荐
- Python3 三种进程创建方法 2023-09-03
- Python详细介绍模型封装部署流程 2022-08-30
- Python数据提取-lxml模块 2023-08-11
- Python实现检测照片中的人脸数 2022-08-30
- 使用 OpenCV-Python 识别答题卡判卷功能 2023-08-08
- 远程和Ubuntu服务器进行Socket通信,使用python和C#(准备篇) 2023-09-05
- Python 对象序列化与反序列化之pickle json详细解析 2023-08-09
- 【转】新装的CentOS 7安装python3 2023-09-03
- 利用Python读取CSV文件并计算某一列的均值和方差 2023-08-04
- CentOS7.4 安装Python3.5 2023-09-03