使用Java代码执行脚本时出错
嗨,我使用了下面的java代码和一个示例NSIS脚本,当我运行这段代码时,我遇到了一个错误 我的Java代码:使用Java代码执行脚本时出错,java,scripting,nsis,Java,Scripting,Nsis,嗨,我使用了下面的java代码和一个示例NSIS脚本,当我运行这段代码时,我遇到了一个错误 我的Java代码: import java.io.IOException; public class SampleClass { /** * @param args */ Process p; public static void main(String[] args) { // TODO Auto-generated method stu
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
java.io.IOException:无法运行程序“makensis.exe”:CreateProcess error=2,系统找不到指定的文件
位于java.lang.ProcessBuilder.start(未知源)
位于java.lang.Runtime.exec(未知源)
位于java.lang.Runtime.exec(未知源)
位于java.lang.Runtime.exec(未知源)
位于SampleClass.main(SampleClass.java:14)
原因:java.io.IOException:CreateProcess error=2,系统找不到指定的文件
在java.lang.ProcessImpl.create(本机方法)
位于java.lang.ProcessImpl。(未知源)
位于java.lang.ProcessImpl.start(未知源)
... 还有5个
为什么会发生此错误?如何解决此错误?您是否从与makensis.exe文件相同的目录运行java代码?如果没有,则需要使用绝对路径hi scobal,它是否正确r.exec(“C:/Users/FSSD/workspace/Snake/makensis.exe sample.nsi”);我也试过了,但它不起作用。当使用绝对路径时,你会遇到同样的异常吗?