2

我有一个 python 脚本来为我安装/卸载一些经常使用的程序,并且在卸载后它还会清理一些快捷方式/文件夹。我曾经使用此代码删除文件夹

os.system('rd /S /Q "{0}\\{1}"'.format(dirname, name))

效果很好。我正在尝试将我的用法转换为os.systemsubprocess.call所以我将上面的行更改为

subprocess.call(['rd', '/S', '/Q', '{0}\\{1}'.format(dirname, name)])

但这给出了错误

The system cannot find the file specified (2)

我必须错误地使用 subprocess.call 但我无法解决。任何帮助将不胜感激,谢谢。

4

1 回答 1

2

不同之处在于os.system默认情况下在子shell中执行,而subprocess.call没有。尝试使用shell=True.

于 2011-06-02T22:15:57.827 回答