dbdii407
dbdii407

Reputation: 825

subprocess and extra args

I'm trying to use the following code:

args = 'LD_LIBRARY_PATH=/opt/java/jre/lib/i386/:/opt/java/jre/lib/amd64/ exec /opt/java/jre/bin/java -Xincgc -Xmx1G -jar craftbukkit-0.0.1-SNAPSHOT.jar'.split()
p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

However, the result I recieve is:

Traceback (most recent call last):
File "launch.py", line 29, in <module>
p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__ errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1228, in _execute_child raise child_exception
OSError: [Errno 2] No such file or directory

Without the LD_LIBRARY_PATH part, it works fine. However, I need it. Thanks for the assistance.

Upvotes: 4

Views: 8107

Answers (2)

Chris R.
Chris R.

Reputation: 96

Here's a method that avoids using the shell:

from subprocess import Popen
from os import environ

env = dict(os.environ)
env['LD_LIBRARY_PATH'] = '/opt/java/jre/lib/i386/:/opt/java/jre/lib/amd64/'
args = ['/opt/java/jre/bin/java', '-Xincgc', '-Xmx1G', '-jar', 'craftbukkit-0.0.1-SNAPSHOT.jar']
p = Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env)

Upvotes: 7

NPE
NPE

Reputation: 500197

Try adding shell = True to the Popen call:

p = subprocess.Popen(args, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

The syntax you're using to set LD_LIBRARY_PATH is a shell syntax, so it's necessary to execute the command through the shell.

Upvotes: 7

Related Questions