今天我試着通過命令行啓動的Minecraft客戶端在Windows 7上它的工作原理!使用此代碼:通過Python子進程啓動的Minecraft不起作用
java -Xmx1024M -Djava.library.path="%APPDATA%\.minecraft\versions\1.7.10\1.7.10-natives" -cp "%APPDATA%\.minecraft\libraries\org\apache\logging\log4j\log4j-api\2.0-beta9\log4j-api-2.0-beta9.jar;%APPDATA%\.minecraft\libraries\org\apache\logging\log4j\log4j-core\2.0-beta9\log4j-core-2.0-beta9.jar;%APPDATA%\.minecraft\libraries\com\ibm\icu\icu4j-core-mojang\51.2\icu4j-core-mojang-51.2.jar;%APPDATA%\.minecraft\libraries\com\mojang\authlib\1.3\authlib-1.3.jar;%APPDATA%\.minecraft\libraries\io\netty\netty-all\4.0.10.Final\netty-all-4.0.10.Final.jar;%APPDATA%\.minecraft\libraries\java3d\vecmath\1.3.1\vecmath-1.3.1.jar;%APPDATA%\.minecraft\libraries\net\sf\trove4j\trove4j\3.0.3\trove4j-3.0.3.jar;%APPDATA%\.minecraft\libraries\net\sf\jopt-simple\jopt-simple\4.5\jopt-simple-4.5.jar;%APPDATA%\.minecraft\libraries\com\paulscode\codecjorbis\20101023\codecjorbis-20101023.jar;%APPDATA%\.minecraft\libraries\com\paulscode\codecwav\20101023\codecwav-20101023.jar;%APPDATA%\.minecraft\libraries\com\paulscode\librarylwjglopenal\20100824\librarylwjglopenal-20100824.jar;%APPDATA%\.minecraft\libraries\com\paulscode\libraryjavasound\20101123\libraryjavasound-20101123.jar;%APPDATA%\.minecraft\libraries\com\paulscode\soundsystem\20120107\soundsystem-20120107.jar;%APPDATA%\.minecraft\libraries\com\google\guava\guava\15.0\guava-15.0.jar;%APPDATA%\.minecraft\libraries\org\apache\commons\commons-lang3\3.1\commons-lang3-3.1.jar;%APPDATA%\.minecraft\libraries\commons-io\commons-io\2.4\commons-io-2.4.jar;%APPDATA%\.minecraft\libraries\net\java\jinput\jinput\2.0.5\jinput-2.0.5.jar;%APPDATA%\.minecraft\libraries\net\java\jinput\jinput-platform\2.0.5\jinput-platform-2.0.5-natives-windows.jar;%APPDATA%\.minecraft\libraries\net\java\jutils\jutils\1.0.0\jutils-1.0.0.jar;%APPDATA%\.minecraft\libraries\com\google\code\gson\gson\2.2.4\gson-2.2.4.jar;%APPDATA%\.minecraft\libraries\org\lwjgl\lwjgl\lwjgl\2.9.0\lwjgl-2.9.0.jar;%APPDATA%\.minecraft\libraries\org\lwjgl\lwjgl\lwjgl_util\2.9.0\lwjgl_util-2.9.0.jar;%APPDATA%\.minecraft\versions\1.7.10\1.7.10.jar" net.minecraft.client.main.Main --username [username] --version 1.7.10 --gameDir C:\Users\Jon\AppData\Roaming\.minec~1 --assetsDir C:\Users\Jon\AppData\Roaming\.minec~1\assets --accessToken [accessToken] --uuid [uuid] --userProperties {} --userType mojang
有點長,但它工作正常,如果您設置用戶名,uuid和accessToken。
現在我想建立與Python(小GUI等)一點點的Minecraft發射臺,我知道我可以調用與子和POPEN的命令。
所以我已經試過POPEN:
import subprocess
# sc = start command
sc = ['java', '-Xmx1024M', '-Djava.library.path="%APPDATA%\\.minecraft\\versions\\1.7.10\\1.7.10-natives"', '-cp', '"%APPDATA%\\.minecraft\\libraries\\org\\apache\\logging\\log4j\\log4j-api\\2.0-beta9\\log4j-api-2.0-beta9.jar;%APPDATA%\\.minecraft\\libraries\\org\\apache\\logging\\log4j\\log4j-core\\2.0-beta9\\log4j-core-2.0-beta9.jar;%APPDATA%\\.minecraft\\libraries\\com\\ibm\\icu\\icu4j-core-mojang\\51.2\\icu4j-core-mojang-51.2.jar;%APPDATA%\\.minecraft\\libraries\\com\\mojang\\authlib\\1.3\\authlib-1.3.jar;%APPDATA%\\.minecraft\\libraries\\io\\netty\\netty-all\\4.0.10.Final\\netty-all-4.0.10.Final.jar;%APPDATA%\\.minecraft\\libraries\\java3d\\vecmath\\1.3.1\\vecmath-1.3.1.jar;%APPDATA%\\.minecraft\\libraries\\net\\sf\\trove4j\\trove4j\\3.0.3\\trove4j-3.0.3.jar;%APPDATA%\\.minecraft\\libraries\\net\\sf\\jopt-simple\\jopt-simple\\4.5\\jopt-simple-4.5.jar;%APPDATA%\\.minecraft\\libraries\\com\\paulscode\\codecjorbis\\20101023\\codecjorbis-20101023.jar;%APPDATA%\\.minecraft\\libraries\\com\\paulscode\\codecwav\\20101023\\codecwav-20101023.jar;%APPDATA%\\.minecraft\\libraries\\com\\paulscode\\librarylwjglopenal\\20100824\\librarylwjglopenal-20100824.jar;%APPDATA%\\.minecraft\\libraries\\com\\paulscode\\libraryjavasound\\20101123\\libraryjavasound-20101123.jar;%APPDATA%\\.minecraft\\libraries\\com\\paulscode\\soundsystem\\20120107\\soundsystem-20120107.jar;%APPDATA%\\.minecraft\\libraries\\com\\google\\guava\\guava\\15.0\\guava-15.0.jar;%APPDATA%\\.minecraft\\libraries\\org\\apache\\commons\\commons-lang3\\3.1\\commons-lang3-3.1.jar;%APPDATA%\\.minecraft\\libraries\\commons-io\\commons-io\\2.4\\commons-io-2.4.jar;%APPDATA%\\.minecraft\\libraries\\net\\java\\jinput\\jinput\\2.0.5\\jinput-2.0.5.jar;%APPDATA%\\.minecraft\\libraries\\net\\java\\jinput\\jinput-platform\\2.0.5\\jinput-platform-2.0.5-natives-windows.jar;%APPDATA%\\.minecraft\\libraries\\net\\java\\jutils\\jutils\\1.0.0\\jutils-1.0.0.jar;%APPDATA%\\.minecraft\\libraries\\com\\google\\code\\gson\\gson\\2.2.4\\gson-2.2.4.jar;%APPDATA%\\.minecraft\\libraries\\org\\lwjgl\\lwjgl\\lwjgl\\2.9.0\\lwjgl-2.9.0.jar;%APPDATA%\\.minecraft\\libraries\\org\\lwjgl\\lwjgl\\lwjgl_util\\2.9.0\\lwjgl_util-2.9.0.jar;%APPDATA%\\.minecraft\\versions\\1.7.10\\1.7.10.jar"', 'net.minecraft.client.main.Main', '--username', '[username]', '--version', '1.7.10', '--gameDir', 'C:\\Users\\Jon\\AppData\\Roaming\\.minecraft', '--assetsDir C:\\Users\\Jon\\AppData\\Roaming\\.minecraft\\assets', '--accessToken', '[accessToken]', '--uuid', '[uuid]', '--userProperties', '{}', '--userType', 'mojang']
p = subprocess.Popen(sc, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
while True:
o = p.stdout.readline()
e = p.stderr.readline()
if o:
print o
if e:
print e
if o or e:
pass
else:
break
它不工作,因爲一個錯誤occures:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/logging/log4j/LogManager
at bao.<clinit>(SourceFile:84)
at net.minecraft.client.main.Main.main(SourceFile:72)
Caused by: java.lang.ClassNotFoundException: org.apache.logging.log4j.LogManager
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
在正常命令行命令工作正常,沒有任何問題,但只在Python中有一個問題。好吧,經過一番思考,我意識到我可以「管」cmd.exe和java命令+參數。
所以,我已經試過了,太:
import subprocess
### as you can see, I've tried to replace the %appdata%-placeholder too
# start command
sc = ['java', '-Xmx1024M', '-Djava.library.path="%APPDATA%\\.minecraft\\versions\\1.7.10\\1.7.10-natives"', '-cp', '"%APPDATA%\\.minecraft\\libraries\\org\\apache\\logging\\log4j\\log4j-api\\2.0-beta9\\log4j-api-2.0-beta9.jar;%APPDATA%\\.minecraft\\libraries\\org\\apache\\logging\\log4j\\log4j-core\\2.0-beta9\\log4j-core-2.0-beta9.jar;%APPDATA%\\.minecraft\\libraries\\com\\ibm\\icu\\icu4j-core-mojang\\51.2\\icu4j-core-mojang-51.2.jar;%APPDATA%\\.minecraft\\libraries\\com\\mojang\\authlib\\1.3\\authlib-1.3.jar;%APPDATA%\\.minecraft\\libraries\\io\\netty\\netty-all\\4.0.10.Final\\netty-all-4.0.10.Final.jar;%APPDATA%\\.minecraft\\libraries\\java3d\\vecmath\\1.3.1\\vecmath-1.3.1.jar;%APPDATA%\\.minecraft\\libraries\\net\\sf\\trove4j\\trove4j\\3.0.3\\trove4j-3.0.3.jar;%APPDATA%\\.minecraft\\libraries\\net\\sf\\jopt-simple\\jopt-simple\\4.5\\jopt-simple-4.5.jar;%APPDATA%\\.minecraft\\libraries\\com\\paulscode\\codecjorbis\\20101023\\codecjorbis-20101023.jar;%APPDATA%\\.minecraft\\libraries\\com\\paulscode\\codecwav\\20101023\\codecwav-20101023.jar;%APPDATA%\\.minecraft\\libraries\\com\\paulscode\\librarylwjglopenal\\20100824\\librarylwjglopenal-20100824.jar;%APPDATA%\\.minecraft\\libraries\\com\\paulscode\\libraryjavasound\\20101123\\libraryjavasound-20101123.jar;%APPDATA%\\.minecraft\\libraries\\com\\paulscode\\soundsystem\\20120107\\soundsystem-20120107.jar;%APPDATA%\\.minecraft\\libraries\\com\\google\\guava\\guava\\15.0\\guava-15.0.jar;%APPDATA%\\.minecraft\\libraries\\org\\apache\\commons\\commons-lang3\\3.1\\commons-lang3-3.1.jar;%APPDATA%\\.minecraft\\libraries\\commons-io\\commons-io\\2.4\\commons-io-2.4.jar;%APPDATA%\\.minecraft\\libraries\\net\\java\\jinput\\jinput\\2.0.5\\jinput-2.0.5.jar;%APPDATA%\\.minecraft\\libraries\\net\\java\\jinput\\jinput-platform\\2.0.5\\jinput-platform-2.0.5-natives-windows.jar;%APPDATA%\\.minecraft\\libraries\\net\\java\\jutils\\jutils\\1.0.0\\jutils-1.0.0.jar;%APPDATA%\\.minecraft\\libraries\\com\\google\\code\\gson\\gson\\2.2.4\\gson-2.2.4.jar;%APPDATA%\\.minecraft\\libraries\\org\\lwjgl\\lwjgl\\lwjgl\\2.9.0\\lwjgl-2.9.0.jar;%APPDATA%\\.minecraft\\libraries\\org\\lwjgl\\lwjgl\\lwjgl_util\\2.9.0\\lwjgl_util-2.9.0.jar;%APPDATA%\\.minecraft\\versions\\1.7.10\\1.7.10.jar"', 'net.minecraft.client.main.Main', '--username', 'Microskype', '--version', '1.7.10', '--gameDir', 'C:\\Users\\Jon\\AppData\\Roaming\\.minecraft', '--assetsDir C:\\Users\\Jon\\AppData\\Roaming\\.minecraft\\assets', '--accessToken', '40b9d172b3fe4e3486e33a67ca3db075', '--uuid', 'e457b026-2e68-40b6-b38d-fcb3645ba318', '--userProperties', '{}', '--userType', 'mojang']
# new start command starting with cmd.exe and /C to pipe cmd.exe and the java command + parameters
nsc = ["cmd.exe", "/C"]
for one in sc:
one = one.replace('%APPDATA%', 'C:\\Users\\Jon\\AppData\\Roaming')
one = one.replace('%appdata%', 'C:\\Users\\Jon\\AppData\\Roaming')
nsc.append(one)
p = subprocess.Popen(nsc, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
while True:
o = p.stdout.readline()
e = p.stderr.readline()
if o:
print o
if e:
print e
if o or e:
pass
else:
break
然後我試着使用整個Java的路徑,而不是Java的,但比我得到WindowsError: [Error 5] Access denied
。命令是否長? :d
我認爲這個問題是Windows,但必須有解決問題的方式。 你有什麼想法嗎?
問候, Jonniboy
Windows命令行限制爲1024個字符。 – tdelaney 2014-09-21 15:48:15
@tdelaney我認爲,但我怎樣才能解決這個問題沒有突破極限? – Jonniboy 2014-09-21 15:53:15
嘗試將-cp字符串放入CLASSPATH環境變量中。 'ENV = os.environ.copy(); ENV [ 'CLASSPATH'] = 「類路徑字符串」; POPEN(...,ENV = ENV)'。 – tdelaney 2014-09-22 01:16:29