I have a Java application and a NSIS script. I need to run the NSIS script via Java code at runtime. I know the following code is used for runtime execution.
Process p = Runtime.getRuntime().exec();
My problem is i don’t know how to execute my script with in exec(). if anyone please tells me how I use this script with in my exe.
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
Thanks in Advance..
Hi i use the following java code:
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 same as above, 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?????
I’m not familiar with NSIS script, but quick Googling showed me I can run the NSIS script like this in command prompt:
makensis.exe myscript.nsiSo in java you can do this:
then you can use
pto get the stdout and stderr text of the execution result. For this to work though you have to make suremakensis.exeis under the directory in yourPATHenvironmental variable.