0

I am executing the python command,

proc = subprocess.Popen(cmd, shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) 

after executing command i want to read the stderr and stdout

res = proc.stderr.read() 

in res i am expecting any error or ' '

but the reading the stderr is taking infinite time is get hang not reading the values what ever the result it.it goes in infinite time.

Some time back same code is working fine but not idea why its not reading stderr now.

Any Hint, thanks.

1 Answer 1

1

Instead of explicitly calling stderr.read(), just do a communicate on the proc.

output, error = proc.communicate() 

That way you would get the output and error by communicating with the process.

Sign up to request clarification or add additional context in comments.

3 Comments

I tried with the same but the reading the proc taking infinite time ,:( dont know why...!!
Shashi, then your process is blocking, the problem is with your cmd which you are passing. It is perhaps waiting for some input. Try a different command, or as you sending stdin to PIPE as well, do proc.communicate('input\n')
@ Senthil Kumaran ok sure i will try that.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.