Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-03-25
8
Medium Priority
?
229 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 80 total points
ID: 10680751
   String wincommand  = "Notepad";
    Runtime rt = Runtime.getRuntime();
    try {
      Process p = rt.exec(wincommand);
    } catch (Exception wine) {
      wine.printStackTrace();
    }
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

972 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