subprocess.call 与 os.system 有何不同 [英] How does subprocess.call differ from os.system
本文介绍了subprocess.call 与 os.system 有何不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 python 脚本来为我安装/卸载一些经常使用的程序,它还会在卸载后清理一些快捷方式/文件夹.我以前用这个代码删除一个文件夹
I have a python script to install/uninstall some regularly used programs for me and it also does some shortcut/folder clean up after uninstall. I used to use this code to delete a folder
os.system('rd /S /Q "{0}\\{1}"'.format(dirname, name))
效果很好.我正在尝试将我对 os.system
的使用转换为 subprocess.call
所以我将上面的行更改为此
which worked just fine. I am attempting to convert my usage of os.system
to subprocess.call
so I changed the above line to this
subprocess.call(['rd', '/S', '/Q', '{0}\\{1}'.format(dirname, name)])
但这给出了错误
The system cannot find the file specified (2)
我一定是错误地使用了 subprocess.call,但我无法解决.任何帮助将不胜感激,谢谢.
I must be using subprocess.call incorrectly but I can't work it out. Any help would be appreciated, thanks.
推荐答案
区别在于 os.system
默认在子 shell 中执行,而 subprocess.call
没有.尝试使用 shell=True
.
这篇关于subprocess.call 与 os.system 有何不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文