使用 JavaCode 执行脚本时出错

发布于 2024-11-19 04:40:59 字数 1915 浏览 2 评论 0原文

您好,我使用以下 java 代码和示例 NSIS 脚本,当我运行此代码时出现错误。

我的 JavaCode:

import java.io.IOException;


public class SampleClass {

    /**
     * @param args
     */
    Process p;
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Runtime r=Runtime.getRuntime();
        try {
            r.exec("makensis.exe myscript.nsi");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}

我的 NSIS 脚本

    OutFile "Your ComputerName.exe"
Name "Your ComputerName"
Caption "ComputerName"
XPStyle "on"

Function .onInit
  ReadRegStr $0 HKLM "System\CurrentControlSet\Control\ComputerName\ActiveComputerName" "ComputerName"
  StrCmp $0 "" win9x
  StrCpy $1 $0 4 3
  MessageBox MB_OK "Your ComputerName : $0" 
  Goto done
win9x:
  ReadRegStr $0 HKLM "System\CurrentControlSet\Control\ComputerName\ComputerName" "ComputerName"
  StrCpy $1 $0 4 3
  MessageBox MB_OK "Your ComputerName : $0" 
done:
  Quit ; placed here so we quit the installer; we dont need the other pages for this example.
FunctionEnd

Section "-boo"
;
SectionEnd

; rest of script

在执行时出现以下错误,

java.io.IOException: Cannot run program "makensis.exe": CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessBuilder.start(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at SampleClass.main(SampleClass.java:14)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(Unknown Source)
    at java.lang.ProcessImpl.start(Unknown Source)
    ... 5 more

为什么会发生如何解决此错误???

Hi i use the following java code and a sample NSIS script while i run this code i got an error.

My JavaCode:

import java.io.IOException;


public class SampleClass {

    /**
     * @param args
     */
    Process p;
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Runtime r=Runtime.getRuntime();
        try {
            r.exec("makensis.exe myscript.nsi");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}

and my NSIS script is

    OutFile "Your ComputerName.exe"
Name "Your ComputerName"
Caption "ComputerName"
XPStyle "on"

Function .onInit
  ReadRegStr $0 HKLM "System\CurrentControlSet\Control\ComputerName\ActiveComputerName" "ComputerName"
  StrCmp $0 "" win9x
  StrCpy $1 $0 4 3
  MessageBox MB_OK "Your ComputerName : $0" 
  Goto done
win9x:
  ReadRegStr $0 HKLM "System\CurrentControlSet\Control\ComputerName\ComputerName" "ComputerName"
  StrCpy $1 $0 4 3
  MessageBox MB_OK "Your ComputerName : $0" 
done:
  Quit ; placed here so we quit the installer; we dont need the other pages for this example.
FunctionEnd

Section "-boo"
;
SectionEnd

; rest of script

while i'm executing i got the following error,

java.io.IOException: Cannot run program "makensis.exe": CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessBuilder.start(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at SampleClass.main(SampleClass.java:14)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(Unknown Source)
    at java.lang.ProcessImpl.start(Unknown Source)
    ... 5 more

Why it happens how to resolve this error?????

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

够钟 2024-11-26 04:40:59

您是否在与 makensis.exe 文件相同的目录中运行 java 代码?如果没有,那么您将需要使用绝对路径

Are you running the java code from the same directory as the makensis.exe file? If not then you will need to use an absolute path

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文