Runtime.getRuntime().exec causing Windows 16-bit error!

P

paul brown

Hi there,

I'm trying to do something i've done many times before without problem, even
from signed applets...
trying to run a system command from Java.

I'm doing this:

import java.io.*;
public class SysCommand{
public static void main(Stirng[] args){
try{
Process proc =
Runtime.getRuntime().exec(
new String[]{"command.com",
"/C",
"echo",
"%windir%"});
BufferedReader reader =
new BufferedReader(
new InputStreamReader(
proc.getInputStream()));
System.out.println(reader.readLine());
proc.waitFor();
proc.destroy();
}
catch(Throwable th){
th.printStackTrace();
}
}
}

I'm trying to find out where the Windows directory is (i need to copy some
DLL's into there as part of an installation process).

When i run this, Windows raises a dialog box saying:

_______________________________________________________________
|16 bit MS-DOS Subsystem
|
|
|
| C:\WINNT\system32\ntvdm.exe
|
| Error while setting up environment for the application. Click 'Close'
to terminate |
---------------------------------------------------------------------------
---------

I'm running JDK 1.4.2_02 on a Win2K box.

Any ideas?

Thanks,
Paul
 
P

paul brown

that's ok..

it should have been

Process proc =
Runtime.getRuntime().exec(
new String[]{"cmd",
"/C",
"echo",
"%windir%"});
BufferedReader reader =

it works now ...

thanks
Paul
 
C

Chris Smith

paul said:
I'm trying to do something i've done many times before without problem, even
from signed applets...
trying to run a system command from Java.

Okay... see below.
Process proc =
Runtime.getRuntime().exec(
new String[]{"command.com",
"/C",
"echo",
"%windir%"});
When i run this, Windows raises a dialog box saying:

_______________________________________________________________
|16 bit MS-DOS Subsystem
|
|
|
| C:\WINNT\system32\ntvdm.exe

You're running this on Windows NT (or a derivative, such as Windows 2000
or XP). The Windows NT command interpreter is called cmd.exe, not
command.com. The command.com interpreter is present, but belongs to
that class of outdated and decaying code that can't be expected to run
reliably.

I don't know exactly what's wrong, but using cmd.exe on Windows NT-based
platforms will almost certainly fix the problem.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
Joined
Feb 17, 2009
Messages
1
Reaction score
0
Hi,

I am getting the same error as mentioned in this thread. Please look into the code below-

-----------------------------------------------------------
try
{
String osName = System.getProperty("os.name" );
String[] cmd = new String[4];
if( osName.startsWith("Win"))
{
cmd[0] = "command.com" ;
cmd[1] = "/C" ;
cmd[2] = "unzip";
cmd[3] = fileName;
}

System.out.println("Execing " + cmd[0] + " " + cmd[1]
+ " " + cmd[2] + " " + cmd[3]);

process = runTime.exec(cmd);
InputStream ins = process.getErrorStream();
BufferedReader bfr = new BufferedReader(new InputStreamReader(ins));
String line = null;
while((line = bfr.readLine()) != null) {
System.out.println(line);
}
int exitval = process.waitFor();
System.out.println("Wait over..." + exitval);



}
catch(IOException ioe)
{
ioe.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
}
---------------------------------------------------------------

I am running the above code on Windows 2000 and the above code runs perfectly fine in eclipse IDE but if I build a jar file and run the jar file from the command prompt, I get the MSDOS 16 bit error and the code hangs there unless I press Close or Ignore.
If i change the code from "command.com" to "cmd.exe", the code hangs at that point itself with no MSDOS error.
Please let me know how to solve this issue.

Thanks in advance!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top