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
Solved

How to call a DOS- or Windows-Program from a Java-Program

Posted on 2004-03-25
8
211 Views
Last Modified: 2010-03-31
The code looks like:

...
...
if(true)
  call_dos_windows_program()  // such as cmd or wordpad
...
...
0
Comment
Question by:chenwei
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 30

Accepted Solution

by:
GrandSchtroumpf earned 20 total points
ID: 10680751
   String wincommand  = "Notepad";
    Runtime rt = Runtime.getRuntime();
    try {
      Process p = rt.exec(wincommand);
    } catch (Exception wine) {
      wine.printStackTrace();
    }
0
 
LVL 92

Expert Comment

by:objects
ID: 10683014
0
 

Author Comment

by:chenwei
ID: 10687164
To GrandSchtroumpf:

It runs if I start "notepad". But if I want to start "wordpad", I got exeptions. And if I want to start a BAT-file, I can see that , though it's started.

Why?
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 30

Expert Comment

by:Mayank S
ID: 10687204
Try running the batch-file like this: cmd.exe /C start cmd.exe BatchFileName
0
 
LVL 92

Expert Comment

by:objects
ID: 10690625
> But if I want to start "wordpad", I got exeptions

what exceptions?
0
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 10690799
the wincommand in my code will work if it works in a command prompt.
if you open a command prompt and type "nodepad", notepad opens.
if you open a command prompt and type "wordpad", you get an error.
it's up to you to find the correct windows command.
if you want to open wordpad for example, you might need to use the complete path for wordpad (i.e. "C:\Program Files\Windows NT\Accessories\wordpad.exe").
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10694517
I guess it would still not open if it does not open from the command prompt. Some programs can only be invoked from inside Windows, and not from the console. I tried Wordpad - gave me exceptions too.
0
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 10712745
:°)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to convert String matching to regex in java 4 49
ejb example issues 3 23
jsp insert to database example 2 45
how to debug htl and js pages 8 39
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

839 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