File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes exec and cmd.exe / on Win Server 2003 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "exec and cmd.exe / on Win Server 2003" Watch "exec and cmd.exe / on Win Server 2003" New topic

exec and cmd.exe / on Win Server 2003

Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
Ok, I've read a bunch of the info in forum posts related to using exec and detecting which version of Windows you're running so you know whether to call cmd.exe or, and also how sometimes when executing a 16-bit program like PkUnzip you can get an error mentioning NTVDM.exe and how your environment is not set up correctly. Here are examples of what I'm talking about:

This problem occurring on Windows Server 2003 isn't mentioned anywhere, and while I wouldn't imagine it being very different from XP or 2000, the solution for Win 2003 wasn't the same as for them, at least according to the code in that second link above. Basically, I first tried to exec PKUNZIP, and then I tried calling exec("", "/c", pathToPKUNZIP...) and that didn't worked, so I changed to cmd.exe and it currently works, though earlier what I had written worked (an exec on PKUNZIP without cmd or and then it stopped working again (and I don't know what I did--opened and closed a few cmd/command windows manually?). When exec is invoked in Windows, do you think it's more similar to or cmd.exe, or is this even worth me asking? I know this is rambling, but I'm just trying to grasp what's going on so I can ensure this works when it needs to! Does it matter that to begin with, my Java program gets invoked from a Windows .bat file? I assume that means it loads up cmd.exe...

Here is my code that uses the old PKUNZIP to unzip a password-protected file:

I changed the first line to this and it currently works:

However, as I mentioned, before it worked for only a few hours and I have no idea whether anyone changed ANYTHING on that server! Any idea as to what is going on?
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

Some windowses have cmd.exe, and some have command.exe.

2000, xp: cmd.exe
95, 98: command.exe

so far I know.

Did you allways use the same zipfile?
Is there some output generated? If yes, this might be an issue, if you don't consume / out.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I'm on XP and I have both cmd and command. Try the help on each. They are not the same.

cmd /?
command /?

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link:
subject: exec and cmd.exe / on Win Server 2003
It's not a secret anymore!