我正在使用Python在Linux机器上自动安装rpm。即时通讯使用plink连接到linux盒。首先,我需要在包装盒上获取已经安装的某些rpm的信息。为此,我是命令
os.system('plink root@server -pw pass rpm -qa|grep string > rpm.txt')
在此,命令行将a解释'|'
为cmd命令,并引发错误“ grep无法识别为内部或外部命令,可操作程序或批处理文件”
也是rpm.txt
在我的机器上而不是在linux盒子上创建的。
无论如何,我可以使用在Linux框中创建的'|'
并且makeure 'rmp.txt'
?
试试这个:
ff=subprocess.Popen("plink root@server -pw pass rpm -qa",shell=False,stdin=subprocess.PIPE)
ff.communicate("grep string > rpm.txt")
一种
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句