aspose file tools
The moose likes Beginning Java and the fly likes how to open new DOS window from java application Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "how to open new DOS window from java application" Watch "how to open new DOS window from java application" New topic
Author

how to open new DOS window from java application

Sankar Ravula
Greenhorn

Joined: Oct 17, 2003
Posts: 3
Hi,
I m running my java application from a command window. I want my java application to open another command window and run the specified batch file in that window. My java code is as follows, its not working
public class MyTestClass
{
public static void main(String args[])
{
System.out.println("Trying to get the Runtime");
Runtime rt = Runtime.getRuntime();
System.out.println("Got the Runtime" + rt);
try
{
rt.exec("C:/WINNT/system32/cmd.exe /C start C:/MyBatchfile.bat");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
Pls... help me in solving the above problem.
Thanks,
Sankar Ravula
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8876

rt.exec("C:/MyBatchfile.bat");


Groovy
Sankar Ravula
Greenhorn

Joined: Oct 17, 2003
Posts: 3
Hi Pradeep,
that wn't work
Sankar
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8876


print the status
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Perhaps the following will work better.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8876

What is the option k?
Jason Kretzer
Ranch Hand

Joined: May 31, 2001
Posts: 280
From running the command
C:\>help CMD
on a Win2k machine, you get a list of the options it takes. Option /K is listed as Carries out the command specified by string bu remains.
So I guess it opens a DOS window and runs the command and then stays open after the command is run.
Best Regards,


Jason R. Kretzer<br />Software Engineer<br />System Administrator<br /><a href="http://alia.iwarp.com" target="_blank" rel="nofollow">http://alia.iwarp.com</a>
Sankar Ravula
Greenhorn

Joined: Oct 17, 2003
Posts: 3
Hi Pradeep,
Thanks, its working
Sankar
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: how to open new DOS window from java application
 
Similar Threads
Runtime.exec() - command line window problem
Closing Applications
problem using the Runtime.exec()
Calling External Files
Two JFrames in one app / event handling