This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
running a dos executable in win95 & 2000
Posted by Andy South on July 04, 2001 at 1:12 PM
I'm writing a GUI to create an input file and run an existing DOS executable. In win2000 I've managed to get the executable to start up in a new dos window which will take keyboard input, just like if it had been started directly from DOS. But I can't get it to do this in Win95 where I have to use command.com rather than cmd.exe. The following code does start up the executable in a new window but its not receptive to keyboard input (despite the fact that typing 'command.com /C START batch.bat' at the dos prompt does work). Any Suggestions ? I do deal with the Input and Error streams using buffers, but don't do anything with the Output stream, as this is uneccessary for win2000 I was assuming that it wouldn't be necessary for win95 either. String osName = System.getProperty("os.name" ); String[] cmd = new String[4]; if( osName.equals( "Windows NT" ) || osName.equals( "Windows 2000" ) ) { cmd[0] = "cmd.exe" ; cmd[1] = "/C" ; cmd[2] = "START"; cmd[3] = "batch.bat"; } else if( osName.equals( "Windows 95" ) || osName.equals( "Windows 98" ) ) { cmd[0] = "command.com" ; cmd[1] = "/C" ; cmd[2] = "START"; cmd[3] = "batch.bat"; } else { System.out.println("Error unrecognised Operating System is : " + osName); } Runtime rt = Runtime.getRuntime(); System.out.println("Execing " + cmd[0] + " " + cmd[1] + " " + cmd[2] + " " + cmd[3]); Process proc = rt.exec(cmd);
Replies:
|