Windows使用subprocess.call()函数

匆匆过客 提交于 2019-12-02 05:04:07

在研究DeblurGan-tf的代码时,运行GOPRO_preprocess.py文件时
subprocess.call(['cp', train_blur[index], os.path.join(args.output_path, 'train/blur/%s'%('_'.join(train_blur[index].split('/')[-3:])))])语句报错系统找不到指定文件。
研究后发现有三个点需要注意:

1. 文件路径使用\\而不是/。虽然/也没有问题,但为了避免疏忽,路径部分全部使用了\\。
2. 'cp'应该替换为'copy'。
3. 函数中应该指定'shell=True'。

最后这句代码被改为:

subprocess.call(['copy', train_blur[index], os.path.join(args.output_path, 'train\\blur\\%s'%('_'.join(train_blur[index].split('\\')[-3:])))], shell=True)

参考资料:
用Python复制文件的9个方法

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!