我在Windows 7 x64機器上手動運行izpack2exe.py腳本時出現同樣的問題。我做了一些調整,python腳本,現在看起來如下:
import os
import sys
import subprocess
import shutil
import optparse
import shlex
def parse_options():
parser = optparse.OptionParser()
parser.add_option("--file", action="append", dest="file",
help="The installer JAR file/files")
parser.add_option("--output", action="store", dest="output",
default="setup.exe",
help="The executable file")
parser.add_option("--with-jdk", action="store", dest="with_jre", default="",
help="The bundled JRE to run the exe independently of the system resources. ") # choosen JDK that may came with the package
parser.add_option("--with-7z", action="store", dest="p7z",
default="7za",
help="Path to the 7-Zip executable")
parser.add_option("--with-upx", action="store", dest="upx",
default="upx",
help="Path to the UPX executable")
parser.add_option("--no-upx", action="store_true", dest="no_upx",
default=False,
help="Do not use UPX to further compress the output")
parser.add_option("--launch-file", action="store", dest="launch",
default="",
help="File to launch after extract")
parser.add_option("--launch-args", action="store", dest="launchargs",
default="",
help="Arguments for file to launch after extract")
parser.add_option("--name", action="store", dest="name",
default="IzPack",
help="Name of package for title bar and prompts")
parser.add_option("--prompt", action="store_true", dest="prompt",
default=False,
help="Prompt the user before extraction?")
(options, args) = parser.parse_args()
if (options.file is None):
parser.error("no installer file has been given")
return options
def create_exe(settings):
if len(settings.file) > 0:
filename = os.path.basename(settings.file[0])
else:
filename = ''
if len(settings.with_jre) > 0:
jdk = os.path.basename(settings.with_jre) #inside the jdk/jre that was given, there must be a bin/java.exe file
jdk = jdk + "\\bin\\javaw.exe"
print(jdk)
settings.file.append(settings.with_jre) #jdk/jre is going in the package
else:
jdk = 'javaw' #java is added somehow to the PATH
if settings.p7z == '7za':
p7z = os.path.join(os.path.dirname(sys.argv[0]), '7za')
else:
p7z = settings.p7z
# really no need right now
# use_shell = sys.platform != 'win32'
if (os.access('installer.7z', os.F_OK)):
os.remove('installer.7z')
files = '" "'.join(settings.file)
p7zcmd = '7za.exe a -mmt -t7z -mx=9 installer.7z "%s"' % files
zip_proc = subprocess.Popen(shlex.split(p7zcmd))
zip_proc.communicate()
config = open('config.txt', 'w')
config.write(';[email protected]@!UTF-8!\n')
config.write('Title="%s"\n' % settings.name)
if settings.prompt:
config.write('BeginPrompt="Install %s?"\n' % settings.name)
config.write('Progress="yes"\n')
if settings.launch == '':
config.write('ExecuteFile="' + jdk + '"\n') # who is going to run my installer.jar?
config.write('ExecuteParameters="-jar \\\"%s\\\"' % filename)
if settings.launchargs != '':
config.write(' %s"\n' % settings.launchargs)
else:
config.write('"\n')
else:
config.write('ExecuteFile="%s"\n' % settings.launch)
if settings.launchargs != '':
config.write('ExecuteParameters="%s"\n' % settings.launchargs)
config.write(';[email protected]@!\n')
config.close()
sfx = os.path.join(os.path.dirname(p7z), '7zS.sfx')
files = [sfx, 'config.txt', 'installer.7z']
output = open(settings.output, 'wb')
for f in files:
in_file = open(f, 'rb')
shutil.copyfileobj(in_file, output, 2048)
in_file.close()
output.close()
if (not settings.no_upx):
if settings.upx == 'upx':
upx = os.path.join(os.path.dirname(sys.argv[0]), 'upx')
else:
upx = settings.upx
upx = 'upx.exe --ultra-brute "%s"' % settings.output
upx_proc = subprocess.Popen(shlex.split(upx))
upx_proc.communicate()
os.remove('config.txt')
os.remove('installer.7z')
def main():
create_exe(parse_options())
if __name__ == "__main__":
main()
我靜把7za.exe在p7zcmd變量,它不會導致問題,因爲它是我的道路上。我阻止了腳本執行,直到完成的子流程(分別爲7zip和upx)解決了我的問題。
希望我能幫助你。
Regards
相同的命令是否從命令行運行?不看我像一個ANT問題。 –
亞相同的命令運行命令行 – developer
類似的問題,與一個公認的答案:http://stackoverflow.com/questions/5538671/python-call-to-external-program-results-in-error-193- 1 - 是 - 不是一個有效-Win32的一個 – sunbabaphu