The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
July 2001

Advertisement

Advertisement
where you can ask and answer Java programming questions.">
artima.com - a resource for Java and Jini developers
Artima | Search | Java | Design | JVM | Jini | Books | Seminars | Subscribe 


Java Answers Forum
July 2001

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:

executable batch (any fixes?)

Posted by W Frymire on January 22, 2002 at 2:09 PM

What solution did you use for this problem? I have the same problem but on a windows 98 with it working fine on 2000.

> 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:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us