Solved

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

Posted on 2004-03-25
8
212 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
[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
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Tomcat: Unable to run tomcat service. 2 29
how to debug htl and js pages 8 53
American Express @Work site and Java 4 63
Java array sort 10 30
In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

735 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