0

So I have:

result = subprocess.check_output(['wine',
                    os.getcwd()+'/static/sigcheck.exe',
                    '-a','-i','-q',
                    self.tmpfile.path()])

But whenever I run this I get this error

CalledProcessError: Command '['wine', '/home/static/sigcheck.exe', '-a', '-i', '-q',     '/tmp/tmpxnsN5j']' returned non-zero exit status 1

But if I change check_output to call it works fine:

Z:\tmp\tmpvOybcm:
    Verified:       Unsigned
    File date:      9:08 AM 10/24/2012
    Publisher:      Hardcore Computer
    Description:    Farthest Emitters Converter
    Product:        Farthest Emitters Converter
    Version:        3.2.0
    File version:   3.2.0
fixme:mscoree:StrongNameSignatureVerificationEx (L"Z:\\tmp\\tmpvOybcm", 1, 0x33ec13): stub
    Strong Name:    Unsigned
    Original Name:  n/a
    Internal Name:  Farthest Emitters Converter
    Copyright:      Hardcore Computer 2006
    Comments:       n/a

Any reason why check_output wouldn't work?

3 Answers 3

6

A non-zero return code is (usually) a way of indicating exit with error by a program. So subprocess.check_output will raise an exception if the returncode of the process is non-zero. If you use:

retcode = call(...)

and then print the return code I guess you will see that it is returning 1.

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

2 Comments

is there a way to capture the output into a variable?
You can use check_output in a try: block and Except CalledProcessError:, but the usual way is just to make a subprocess.Popen object with pipes for stdout, stderr and then use it's communicate method.
3

To get output in a string without raising an error on non-zero exit status:

p = Popen(['wine',...], stdout=PIPE)
output = p.communicate()[0]

check_output() executes rc = p.poll() after p.communicate() and raises an error if bool(rc) == True.

Comments

1

Alternative way

proc = subprocess.Popen(['wine',
                    os.getcwd()+'/static/sigcheck.exe',
                    '-a','-i','-q',
                    self.tmpfile.path()], stdin=subprocess.PIPE,  stdout=subprocess.PIPE)
stdout = proc.stdout.read()

2 Comments

It is preferred to use communicate() rather than .stdout.read to avoid deadlocks due to any of the other OS pipe buffers filling up and blocking the child process.
Roger. Thanks for the warning

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.