2012-06-13 68 views
0

蔭越來越下面的錯誤,而使用建築物螞蟻建築工具同時使用Ant工具IAM得到以下錯誤

installer.izpack.exe: 
    [exec] Traceback (most recent call last): 
    [exec] File "C:\PROGRA~1\IzPack/utils/wrappers/izpack2exe/izpack2exe.py", line 126, in <module> 
    [exec]  main() 
    [exec] File "C:\PROGRA~1\IzPack/utils/wrappers/izpack2exe/izpack2exe.py", line 123, in main 
    [exec]  create_exe(parse_options()) 
    [exec] File "C:\PROGRA~1\IzPack/utils/wrappers/izpack2exe/izpack2exe.py", line 77, in create_exe 
    [exec]  subprocess.call(p7zcmd, shell=use_shell) 
    [exec] File "C:\Python27\lib\subprocess.py", line 493, in call 
    [exec]  return Popen(*popenargs, **kwargs).wait() 
    [exec] File "C:\Python27\lib\subprocess.py", line 679, in __init__ 
    [exec]  errread, errwrite) 
    [exec] File "C:\Python27\lib\subprocess.py", line 896, in _execute_child 
    [exec]  startupinfo) 
    [exec] WindowsError: [Error 193] %1 is not a valid Win32 application 

BUILD FAILED 
E:\Java Projects\Spark Projects\EastIT - Copy\build\build.xml:873: exec returned: 1 

下面是它得到錯誤代碼。

<target name="installer.izpack.exe" depends="installer.izpack" description="build release executable izpack installer"> 
     <exec executable="python" failonerror="true"> 
      <arg line="${installer.izpack.dir}/utils/wrappers/izpack2exe/izpack2exe.py"/> 
      <arg line="--file=${basedir}/installer/EasyIT-installer.jar"/> 
      <arg line="--output=${basedir}/installer/EasyIT-installer.exe"/> 
      <arg line="--no-upx"/> 
     </exec> 
    </target> 

請誰能想出如何解決這個問題?

+0

相同的命令是否從命令行運行?不看我像一個ANT問題。 –

+0

亞相同的命令運行命令行 – developer

+0

類似的問題,與一個公認的答案:http://stackoverflow.com/questions/5538671/python-call-to-external-program-results-in-error-193- 1 - 是 - 不是一個有效-Win32的一個 – sunbabaphu

回答

2

我在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

相關問題