Question

I am very new to python and I got a script at my job I need to figure out.

My script parses output of a some exe file (let's call it Mywork.exe ) which processes another binary files (let's call it processedBinary). Now, my scrpit at some point want's to take the name of a processedBinary and do a objdump on it. I can see that previous author (for me unreachable) has used this line sys.argv[1] to get a name of processedBinary. My script processes the output of MyWork.exe. So far, the only way for me to call script successfully is by running:

MyWork.exe processedBinary | /usr/bin/python ./myScript.py -v

And then my script processes output correctly, but it doesn't acquires the name of processedBinary at all (instead sys.argv[1] is actually "-v"). So, I have a couple of questions:

1) Is there a better way of running my script so that sys.argv[1] is name of processedBinary? 2) if the answer on previous question is no, is there a way to acquire name of processedBinary on some better way? 3) Do you have some better suggestions about the implementation/invocation of script, maybe?

Thank you in advance!

Était-ce utile?

La solution

You could call MyWork.exe from the Python script and pass the name of processedBinary to that script.

import subprocess
import sys
command = 'MyWork.exe %s' % (sys.argv[1])
proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
proc.wait()
output = (proc.stdout.read(), proc.stderr.read())

output is now a tuple of stdout and stderr of MyWork.exe

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top