0
您好我使用下面的java代碼和一個示例NSIS腳本,而我運行此代碼時出現錯誤。使用JavaCode執行腳本時出錯
我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
爲什麼會發生如何解決這個錯誤?????
您好scobal,是否正確r.exec(「C:/Users/FSSD/workspace/Snake/makensis.exe sample.nsi」);我也試過這個,但它不起作用 – Aerrow
當你使用絕對路徑時你會得到同樣的異常嗎? –
雅,是否正確..這裏sample.nsi是我的腳本文件 – Aerrow