Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'incorrect function' is returned from exec when calling java

Tags:

inno-setup

I'm calling cmd to excute java, but the resultcode is always 1,after checking, I found it represents 'incorrect function'. My code is like:

Exec('cmd', '/c C:\Program Files\jre\bin\java -version','' , SW_HIDE,   ewWaitUntilTerminated, ResultCode);

I also call, the following code, it doesn't work either:

 Exec('cmd', '/c "C:\Program Files\jre\bin\java -version"','' , SW_HIDE,  ewWaitUntilTerminated, ResultCode);

if I call the following code, it works

 Exec('cmd', '/c java -version','' , SW_HIDE, ewWaitUntilTerminated, ResultCode);

It seems the the space in the java path` can not be recognized. Does anyone know how to correct it?

like image 462
xiaohei Avatar asked Feb 11 '26 21:02

xiaohei


1 Answers

Your first attempt failed, due to a space in the file path, which was not enclosed by double quotes. Your second attempt failed because you've enclosed into double quotes except the file path also the passed parameter -version. And, in both cases you are missing .exe at the end of the application path.

You can try it this way instead:

Exec('cmd', '/c ""C:\Program Files\jre\bin\java.exe" -version"', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);

But, I'm missing here the reason for executing it through the cmd shell. I suppose you can do it directly by calling java.exe this way:

Exec('C:\Program Files\jre\bin\java.exe', '-version', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);

Just one offtopic note, are you sure the java.exe will be always in C:\Program Files\jre\bin\ ?

like image 171
TLama Avatar answered Feb 16 '26 06:02

TLama