I am trying to use the python subprocess to invoke a third party command ParseAddress
. The command ParseAddress
prints out a line of text asking a user to input a list of addresses, then, based on the input it prints out stack trace info. If I manually run the command, it looks like:
$ParseAddress Appname <- Run the command in console
Paste the addresses - new line to continue
[0]0xaaaaaaaa <- a User paste a list of address here
[1]0xbbbbbbbb
[2]0xcccccccc
<- the user type 'enter' to continue
Stack Trace info: <-- results of running the ParseAddress
0xaaaaaaaa: Test::info::Runtest
0xbbbbbbbb: Test::info::SingleTestCase
0xcccccccc: ...
So, I thought the subprocess() and communicate() would be helpful in this case if I already has a list addresses in text format:
cmd = subprocess.Popen([ParseAddress, Appname], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT)
output, error = cmd.communicate(input="[0]0xaaaaaaaa\n[1]0xbbbbbbbb\n[2]0xcccccccc\n\n")
print(output)
The when I use the subprocess with communite(), the console output is:
$ParseAddress Appname
Paste the addresses - new line to continue
0xaaaaaaaa: ?? ??:0 <- subprocess.PIPE?
0xbbbbbbbb: ?? ??:0
0xcccccccc: ?? ??:0
Stack Trace info: <-- no results from the ParseAddress since the address info are in incorrect format
If I use
cmd.communicate(input="[0]0xaaaaaaaa\r\n[1]0xbbbbbbbb\r\n[2]0xcccccccc\r\n\r\n")
The result is:
$ParseAddress Appname
Paste the addresses - new line to continue
<-- No address here, no ideas why
Stack Trace info:
My question is why the parameters are changed from [0]0xaaaaaaaa
to 0xaaaaaaaa: ?? ??:0
?
What is the correct way to use communication()?
environment:
Ubuntu 18.04
Python 2.7.16 :: Anaconda, Inc.