0

Calling

import subprocess
print subprocess.Popen(['java', '-version'])

Gives the error

OSError: [Errno 8] Exec format error

But that can be fixed by changing the above to,

print subprocess.Popen(['java', '-version'], executable='/bin/sh')

How can I fix sh.Command the same way?

import sh
print sh.Command('java').bake('-version')()

Because it then gives the exact same error,

OSError: [Errno 8] Exec format error

2 Answers 2

1

Try this

if sys.platform == 'darwin':
    java = sh.Command('/bin/sh').bake('java')
else:
    java = sh.Command('java')

print java.bake('-version')()
Sign up to request clarification or add additional context in comments.

Comments

0

@nosklo's answer definitely does do what I asked, and I'll keep it as the correct answer, but that wasn't what my problem was.

Basically, as @nosklo hinted at on irc, this error comes when there's confusion between files, treating a binary like a script, or a script like a binary. So that points definitely to java on the build machine.

which java
/usr/bin/java
ls -la /usr/bin/java
/usr/bin/java -> java.new
cat /usr/bin/java
' java.old -Djava.awt.headless=true "$@" '
ls -la /usr/bin/java.old
/usr/bin/java.old -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java

My Java, /usr/bin/java, was a symlink to an executable script, java.new file without a shebang, which forwarded everything to java.old, which was a symlink to the main Java...

Talk about convoluted, but hopefully this might help someone who can't take the easy out the was available to me.

Comments

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.