Solved

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

Posted on 1997-10-03
5
1,214 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
what is the difference between "sudo su" and "su - root" 6 106
web services creation SOAP vs REST 5 20
map related example 6 38
factorial example 4 35
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

867 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

12 Experts available now in Live!

Get 1:1 Help Now