I am using Python to automate installation of rpms on a linux box. i m using plink to connect to the linux box. First I need to get the info of already installed certain rpms on the box. for this i am the command

os.system('plink root@server -pw pass rpm -qa|grep string > rpm.txt')

Here the command line interpreters the '|' as a cmd command and throws the error "grep is not recognized as an internal or external command, operable program or batch file"

Also the rpm.txt is created on my machine instead on the linux box.

Anyway i can use the '|' and also makesure that 'rmp.txt' is created in the linux box?

有帮助吗?

解决方案

Try this:

ff=subprocess.Popen("plink root@server -pw pass rpm -qa",shell=False,stdin=subprocess.PIPE) 
ff.communicate("grep string > rpm.txt")

A

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top