Windows中的Python子进程

问题描述 投票:1回答:1

我尝试在Windows中使用Python 3.6.3子进程的“ren”命令

码:

import subprocess, os

path = r"C:\Users\user\Desktop\Temp"

subprocess.check_output(["ren", os.path.join(path, "ABC.txt"), os.path.join(path, "Hello.txt")], shell=True)

但我得到错误:“subprocess.CalledProcessError”

请帮忙!!

谢谢

python subprocess
1个回答
3
投票

根据ren命令手册,您只能设置更改当前文件而不是驱动器和文件夹所需的文件名:

试试固定代码

import subprocess, os

path = r"C:\Users\user\Desktop\Temp"

subprocess.check_output(["ren", os.path.join(path, "ABC.txt"), "Hello.txt"], shell=True)
© www.soinside.com 2019 - 2024. All rights reserved.