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

Q&A's, tips, howto's
Locked
csfreebird
Posts: 107
Joined: Tue Jan 15, 2013 11:54 am
Location: China, Beijing
Contact:

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

Post by 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
Posts: 107
Joined: Tue Jan 15, 2013 11:54 am
Location: China, Beijing
Contact:

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

Post by csfreebird »

My Windows 7 and installed JDK are both 64 bit.
But it seems the newlisp is 32 bit?
Did this cause my problem?

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

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

Post by Lutz »

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:

Code: Select all

> (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
Posts: 107
Joined: Tue Jan 15, 2013 11:54 am
Location: China, Beijing
Contact:

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

Post by csfreebird »

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.
Last edited by csfreebird on Fri Mar 01, 2013 2:14 am, edited 3 times in total.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

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

Post by Lutz »

At least now you get the ouput of exec returned.

Try:

Code: Select all

(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
Posts: 107
Joined: Tue Jan 15, 2013 11:54 am
Location: China, Beijing
Contact:

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

Post by csfreebird »

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
Posts: 107
Joined: Tue Jan 15, 2013 11:54 am
Location: China, Beijing
Contact:

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

Post by csfreebird »

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 Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NTRU Cryptosystems\NTRU TCG Software Stack\bin\;C:\Program Files\NTRU Cryptosystems\NTRU TCG Software Stack\bin\;C:\Program Files\Dell\Dell Data Protection\Access\Advanced\Wave\Gemalto\Access Client\v5\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\Common Files\Roxio Shared\DLLShared\;C:\Program Files (x86)\Common Files\Roxio Shared\OEM\DLLShared\;C:\Program Files (x86)\Common Files\Roxio Shared\OEM\DLLShared\;C:\Program Files (x86)\Common Files\Roxio Shared\OEM\12.0\DLLShared\;C:\Program Files (x86)\Roxio\OEM\AudioCore\;C:\Program Files\Java\jdk1.6.0_41\bin;C:\apache-maven-3.0.4\bin;c:\portal\mysql-5.5.9-winx64\bin;c:/portal/glassfish\bin;C:\softwares\curl-7.23.1-win64-ssl-sspi;C:\Program Files (x86)\Git\bin;C:\softwares\apache-ant-1.8.2\bin;C:

Locked