python - Reading from and writing to process using subprocess -


i have been (unsuccessfully) trying use python's subprocess module interact executable program. program simple command line based script.

it acts in following way: prompt user text, wait numeric input, prompt more text, wait next input, etc.

so set subprocess so

from subprocess import popen, pipe p = popen('filename.exe', stdin=pipe, stdout=pipe) 

then first prompt

print p.stdout.readline() 

properly returns

enter value blah blah

great! try enter desired value

p.stdin.write('10.0') 

it hangs. can try grabbing next prompt

print p.stdout.readline() 

but still hangs no matter what.

what proper way 1 line read/write business? must messing write line think.

you forgetting output newline:

p.stdin.write('10.0\n') 

what happens subprocess receiving data, waiting more input, until finds newline. if wait output process in state, deadlock system.


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -