gpt4 book ai didi

Windows 中的 Python 子进程

转载 作者:行者123 更新时间:2023-11-30 22:24:19 26 4
gpt4 key购买 nike

我尝试在 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”

请帮忙!!

谢谢

最佳答案

根据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)

关于Windows 中的 Python 子进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47857118/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com