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?
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\ ?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With