不知道大家是否了解ruby on rails框架,这个安装有点麻烦,我就写了个自动安装和卸载的脚本,其中卸载的代码如下:
- Python code
import subprocess DEBUG = True def 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 所有组件都已成功卸载')
可是遇到点问题,当卸载rails和rake的时候,会出现这个提示,需要手动输入y再按回车才会继续:
subprocess.Popen()函数没有办法在子进程运行到一半的时候再给它输入参数,并且由于子进程没运行完这个提示也不会出现在pythonGUI上,虽然只要输入y再按回车便可继续,但用户看起来肯定是认为卡死了。
该怎么解决这个问题呢?
------解决方案--------------------
看不到图片。
subprocess.Popen()函数没有办法在子进程运行到一半的时候再给它输入参数?