(exec "java -version") doesn't work on Windows7

Started by csfreebird, February 27, 2013, 10:41:23 PM

Previous topic - Next topic

csfreebird

When I run java -version command directly in console on my windows 7, it works, gets the following output:

>java -version

java version "1.6.0_41"

Java(TM) SE Runtime Environment (build 1.6.0_41-b02)

Java HotSpot(TM) 64-Bit Server VM (build 20.14-b01, mixed mode)



Then I launch newlisp session, but get unexpected message:

>newlisp

newLISP v.10.4.6 on Win32 IPv4/6 UTF-8 libffi, execute 'newlisp -h' for options.



> (exec "java -version")

'java' is not recognized as an internal or external command,

operable program or batch file.

()



Any idea?

csfreebird

#1
My Windows 7 and installed JDK are both 64 bit.

But it seems the newlisp is 32 bit?

Did this cause my problem?

Lutz

#2
java -version doesn't write the output to standard out (stdout)  but to standard error (stderr). The newLISP exec function only captures stdout not stderr, and an empty list () is returned.



But you can redirect stderr to stdout. Do the following:


> (exec "java -version 2>&1")
("java version "1.6.0_41"" "Java(TM) SE Runtime Environment (build 1.6.0_41-b02-445-11M4107)"
 "Java HotSpot(TM) 64-Bit Server VM (build 20.14-b01-445, mixed mode)")

> (first (exec "java -version 2>&1"))
"java version "1.6.0_41""
>
>


The 2>&1 redirects stderr to stdout.

csfreebird

#3
Hello Lutz:

  I copied your command and executed it , still got error message:

> (exec "java -version 2>&1")

("'java' is not recognized as an internal or external command," "operable program or batch file.")



It seems my newlisp can't find java command correctly.

Lutz

#4
At least now you get the ouput of exec returned.



Try:
(exec "cmd /c java -version 2>&1")

this starts a new command shell, which perhaps has the PATH set correctly for the java command. If that doesn't work, specify the full path for the java command.

csfreebird

#5
Still wrong. Rebooting my OS was not helpful too.



> (exec "cmd /c c:\windows\system32\java.exe -version 2>&1")

("'c:\windows\system32\java.exe' is not recognized as an internal or external command,"

 "operable program or batch file.")



My java.exe is installed under c:\windows\system32 folder.



My newlisp is installed under c:\windows\system32 folder. And there is only one newlisp.exe file under this folder. My installation way of newlisp is very simple, just copy newlisp.exe to system32 folder.



After launching newlisp.exe, the environment NEWLISPDIR uses default value:

> (env "NEWLISPDIR")

"C:\Program Files (x86)/newlisp"



But it's wrong, I have not the above folder under c:\program files (x86).

csfreebird

#6
It works for me now.

I found the jdk path is wrong in my path environment. After changing it, it works now.

Don't know how does newlisp search the path for java.exe?

Below is the correct value of my path environment variable.



C:Program FilesCommon FilesMicrosoft SharedWindows Live;C:Program Files (x86)Common FilesMicrosoft SharedWindows Live;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;C:Program Files (x86)NTRU CryptosystemsNTRU TCG Software Stackbin;C:Program FilesNTRU CryptosystemsNTRU TCG Software Stackbin;C:Program FilesDellDell Data ProtectionAccessAdvancedWaveGemaltoAccess Clientv5;C:Program Files (x86)Windows LiveShared;C:Program Files (x86)Common FilesRoxio SharedDLLShared;C:Program Files (x86)Common FilesRoxio SharedOEMDLLShared;C:Program Files (x86)Common FilesRoxio SharedOEMDLLShared;C:Program Files (x86)Common FilesRoxio SharedOEM12.0DLLShared;C:Program Files (x86)RoxioOEMAudioCore;C:Program FilesJavajdk1.6.0_41bin;C:apache-maven-3.0.4bin;c:portalmysql-5.5.9-winx64bin;c:/portal/glassfishbin;C:softwarescurl-7.23.1-win64-ssl-sspi;C:Program Files (x86)Gitbin;C:softwaresapache-ant-1.8.2bin;C: