Solved

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

Posted on 2004-03-25
8
209 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
use lov values 2 50
Configure a Bean in an XML file 4 33
runtime exception 2 29
Android development question 2 38
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

821 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