How does subprocess.call differ from os.system

℡╲_俬逩灬. 提交于 2019-12-02 05:21:53

问题


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

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)])

but this gives the error

The system cannot find the file specified (2)

I must be using subprocess.call incorrectly but I can't work it out. Any help would be appreciated, thanks.


回答1:


The difference is that os.system excutes in a subshell by default, whereas subprocess.call does not. Try using shell=True.



来源:https://stackoverflow.com/questions/6220157/how-does-subprocess-call-differ-from-os-system

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