还是关于子进程的问题。。唉!
不知道大家是否了解ruby on rails框架,这个安装有点麻烦,我就写了个自动安装和卸载的脚本,其中卸载的代码如下:
import subprocessDEBUG = Truedef Uninstallation(filename): try: print('开始卸载'+filename) cmd=['gem','uninstall',filename] if DEBUG: print('正在执行卸载'+filename) fd = subprocess.Popen(cmd,stdout=subprocess.PIPE,shell=True) #查看子进程输出 stdout_tmp = fd.stdout.read() stdout = stdout_tmp.decode() print(stdout) print('已完成卸载'+filename+'\n') except Exception as e: print('卸载'+filename+'过程遇到问题,请重新卸载') print(e) exit()if __name__ == '__main__': Uninstallation('rails') Uninstallation('activeresource') Uninstallation('actionmailer') Uninstallation('actionpack') Uninstallation('activerecord') Uninstallation('activesupport') Uninstallation('mysql') Uninstallation('rack') Uninstallation('rake') print('Ruby On Rails 所有组件都已成功卸载')