[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 1997-10-03
5
Medium Priority
?
1,272 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 400 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

656 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