Solved

How do I hide the MSDOS window in a Java exec( <DOS cmd> )?

Posted on 1997-10-03
5
1,207 Views
Last Modified: 2013-11-18
I'm using Java's Runtime.exec() to set the parameters of a serial port (WinNT40). This works fine, except that the mode.com file needs a command interpreter to run. This too, is o.k., but in the process of running it flashes an MSDOS window on the screen. Does anyone know of a way to hide this  annoying feature?

I'd like this to run without the MSDOS window popping up and disappearing. BTW, I tried removing the "cmd.exe /c" part of the exec command, but that results in the mode command hanging my application and keeping the port busy until I kill it with NT's task manager. I've also tried adding the /q switch to NT40's cmd.exe but the pop-up window persisted.  Maybe this is an MSDOS question...

Anyway, here is the code (JVM 1.1). If anyone can find me a work-around I'd appreciate it!  
 
 

import java.io.*;

public class SerialTest
{
        public static void main( String args[] )
        {
                Runtime rt = Runtime.getRuntime();
                Process p = null;
                String portname = "com1:";
                String cmd[] = {"c:\\winnt\\system32\\cmd.exe", "/c",
                                               
"c:\\winnt\\system32\\mode.com", portname,
                                                "baud=9600", "parity=n",
"data=8",
                                                "stop=1", "to=on",
"xon=on", "octs=off", "odsr=off",
                                                "dtr=hs", "rts=hs" };
                try
                {
                        p = rt.exec( cmd );
                        if( p.waitFor() != 0 )
                        {
                                System.out.println("Error executing
command: " + cmd );
                                System.exit( -1 );
                        }
                        byte data[] = "This is a test of Java writing a
byte stream out of a serial port.".getBytes();
                        FileOutputStream fos = new FileOutputStream(
portname );
                        BufferedOutputStream bos = new
BufferedOutputStream( fos );
                        fos.write( data, 0, data.length );
                        fos.close();
                }
                catch( Exception e )
                {
                        System.out.println("exception: " +
e.getMessage());
                        e.printStackTrace();
                }
        }
}

0
Comment
Question by:roy020697
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:eugenem
ID: 1227896
Try this:
start /min cmd /c mode.com ...
0
 
LVL 1

Author Comment

by:roy020697
ID: 1227897
Eugene,

It sounded promising, but flamed out when implemented. The start command works fine from the command line, but does not work via Java Runtime.exec( "start", "/min", "cmd.exe" ...). I tried to find the "start" command on my hard drive, but it does not exist as an executable file. I guess it is an internal command.

The windows help example for start says that it will start an application from the command prompt. However, it is the command line interpreter "cmd.exe" which is causing my problem in the first place :-(

Thanks for the suggestion. Too bad it doesn't solve my problem.
0
 
LVL 3

Accepted Solution

by:
eugenem earned 200 total points
ID: 1227898
May be this will work?
cmd /c start /min mode.com
0
 
LVL 1

Author Comment

by:roy020697
ID: 1227899
That did the trick! I'd give you a better grade if:
1. you tried your solutions yourself first
2. you had the right answer the first time

If you did (1.) first, (2.) would be unnecessary.
Still, my problem is solved. I thank you very much!
0
 

Expert Comment

by:xjeffk
ID: 2781102
nice!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now