Reputation: 79
I want to do something likethis using pexpect
echild = pexpect.spawn('/bin/bash -c "sysinfo -v | grep "SCM"')
fout = file('/home/kiva/release_file.txt' , 'w+')
child.logfile = fout
The problem is that I want the out of that command into a textfile but I have to start a shell since we cannot use pipe in spawn(). The bash shell does not understand sysinfo -v and complains about it.
Do you guys have any idea or know of a way in which I can get the desired output into the file without opening the bash terminal? I can solve the issue by just using the spawn() method without grepping it but I want the exact match and hence grep is necessary.
Thank you
Upvotes: 0
Views: 817
Reputation: 771
From your short example I do not see why you specifically need to use pexpect to achieve this. I would go for the Popen
way. Here's a link that might prove useful:
Replacing shell pipeline - Popen
Upvotes: 1