I am trying to start a Java application with Python using the subprocess module. I am not new to Python but I am new to the subprocess module. When I try to run this code:
import subprocess as sp
proc = sp.Popen(["java", "-Xmx1536M -Xms1536M", "-jar /home/bekk/MServer/ForgeBukkit/MCPC.jar"],stdin=sp.PIPE,stdout=sp.PIPE,)
The command:
java -Xmx1536M -Xms1536M -jar /home/bekk/MServer/ForgeBukkit/MCPC.jar
runs correctly when typed into a terminal, so I know that it can work. It seems to be a problem with running it from Python. Any thoughts on what my problem might be?
You're passing "-Xmx1536M -Xms1536M"
as a single argument.
That's not equivalent to this shell command:
java -Xmx1536M -Xms1536M -jar /home/bekk/MServer/ForgeBukkit/MCPC.jar
… but to this one:
java '-Xmx1536M -Xms1536M' -jar /home/bekk/MServer/ForgeBukkit/MCPC.jar
So, Java will get that '-Xmx1536M -Xms1536M'
as its argv[1]
, instead of getting one flag in argv[1]
and the next in argv[2]
. And it will interpret that one giant flag arg as you trying to set mx
to '1536M -Xms1536M'
, which is not a valid maximum heap size.
To fix it, put each argument in its own string in the list:
["java", "-Xmx1536M", "-Xms1536M", "-jar", "/home/bekk/MServer/ForgeBukkit/MCPC.jar"]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.