0

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

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
andybandy12
  • 69
  • 2
  • 8

1 Answers1

1

From your short example I do not see why you specifically need to use pexpect to achieve this. I would go for the Popenway. Here's a link that might prove useful:

Replacing shell pipeline - Popen

Catalin Luta
  • 711
  • 4
  • 8