Results 1 to 1 of 1
I've been trying to write a python script that will create a subprocess. And depending on it's output send it some input. I am not a very experienced programmer at ...
- 07-20-2008 #1Just Joined!
- Join Date
- Jul 2008
- Posts
- 1
Is there any good sub process communication in python?
I've been trying to write a python script that will create a subprocess. And depending on it's output send it some input. I am not a very experienced programmer at this point. But I am getting the feel for it/python at least. Anyway, what I would like to do is essentially this:
is this possible?Code:w = True child = spawn('/usr/bin/someprocess --some --option') while w == True: if child.in_output('some string'): #in_output is basically me saying search the output for this string if it is found return true else false. child.send('something') elif child.in_output('some other string'): child.send('some other thing') else: child.kill() w = False
I have looked into subprocess.Popen, which is ridiculously complicated. and won't work because one of the outputs I am testing for will be a password prompt which is sent directly to the tty and not to stdout. I have also looked into pexpect. which can cope with the password prompts because it creates it's own fake tty for the subprocess, but seems to be severely limited. in that it can only move in a linear spawn expect send expect send expect kill type of motion which is not what I need.
Is there a better option that will give me behavior more similar to the psudo code example I wrote above?


Reply With Quote