Results 1 to 20 of 20
Thread: Launching an exe
- 01-17-2011, 12:22 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
Launching an exe
Hi All,
I am trying to launch an exe from JAVA using
Process p = Runtime.getRuntime().exec(exeLocation);
This launches the exe but the problem is when I double click on the exe, it opens a command prompt as a console, which gets minimized on the taskbar.
I am not able to get this command prompt when launching the exe from the code.
Please help.
- 01-17-2011, 12:36 PM #2
What is the executable that you are launching?
Can you provide some more code? The details provided by you are not sufficient.
GoldestJava Is A Funny Language... Really!.gif)
Click on * and add to member reputation, if you find their advices/solutions effective.
- 01-17-2011, 03:00 PM #3
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,619
- Rep Power
- 5
Do you want to retrieve the output from the exe or communicate in some way? Get the InputStream/OutputStream from the Process and read/write as needed.
- 01-18-2011, 04:29 AM #4
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
The exe that i am trying to launch is an application made in Visual Studio & the command prompt that it shows on double click is nothing but a console.
However, I am unable to see this console/command prompt on launching the exe through the java code.
Code snippet :
String s;
Process p = Runtime.getRuntime().exec(exelocation);
BufferedReader inputReader =new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((s = inputReader.readLine()) != null) {
System.out.println(s);
}
input.close();
- 01-18-2011, 05:18 AM #5
-
Have you seen probably one of the most referenced Java links on potential problems and solutions when using runtime exec? When Runtime.exec() won't
- 01-18-2011, 06:08 AM #7
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
Yes, I am providing the correct path with the extension. That's why I am able to launch the exe.
The problem is not with launching the exe, it is about showing the console (a command prompt) attached with it. Currently, it is not showing.
- 01-18-2011, 07:02 AM #8
What usually happens when you manually open your exe file? Does it opens that console in the first place, which you are talking about? If yes, then it should happen the same way through java.
Do you need to click somewhere or pass any commands to have that console appear? If that's the case then you have to make sure that you are passing all those supplementary things through your code as well.
It would be nice if you can put your whole code instead of bunches.
GoldestJava Is A Funny Language... Really!.gif)
Click on * and add to member reputation, if you find their advices/solutions effective.
- 01-18-2011, 07:21 AM #9
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
When I manually open the exe (double clicking on the shortcut), the console opens.
public class Process {
public static void main(String args[]) {
String s;
Process p = Runtime.getRuntime().exec(exelocation);
BufferedReader inputReader =new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((s = inputReader.readLine()) != null) {
System.out.println(s);
}
inputReader.close();
}
}
On running the main class, the application launches w/o the console.
- 01-18-2011, 07:37 AM #10
This seems more of a naming conflict. We already have the Process class in the java.lang package. This might spoil the things.
Can you simply change your public class name to something else than Process ? Make it Process1 or something and re-run the program.
See what happens?
GoldestJava Is A Funny Language... Really!.gif)
Click on * and add to member reputation, if you find their advices/solutions effective.
- 01-18-2011, 08:16 AM #11
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
- 01-18-2011, 08:35 AM #12
Java Is A Funny Language... Really!.gif)
Click on * and add to member reputation, if you find their advices/solutions effective.
- 01-18-2011, 08:50 AM #13
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
public class TestExe {
public static void main(String args[]) throws InterruptedException,IOException {
String s;
Process p = Runtime.getRuntime().exec(exelocation);
BufferedReader inputReader =new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((s = inputReader.readLine()) != null) {
System.out.println(s);
}
inputReader.close();
}
}
- 01-18-2011, 09:05 AM #14
I am assuming that you have used the import statements correctly. In the same code given by you, I just placed the path to one of my executable, like,
Java Code:Process p = Runtime.getRuntime().exec("C:/Program Files/Internet Explorer/iexplore.exe");
When I ran this, it just worked fine. It opened the internet explorer for me. I wonder how you are getting issues in launching your exe file.
What is the path you are providing for "exelocation"? Could you please post it here? In fact your code never declared this String or passed it to the exec method. From where are you passing this?
GoldestJava Is A Funny Language... Really!.gif)
Click on * and add to member reputation, if you find their advices/solutions effective.
- 01-18-2011, 09:15 AM #15
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
I do not have a problem in launching the exe.
The problem is that the application that I am launching has a console which doesn't show when I execute/launch it using :
Runtime.getRuntime().exec(<some exe location>);
- 01-18-2011, 09:34 AM #16
It shouldn't happen basically. If this is the only exe file that is responsible for launching your application, then it should come along with all the features.
Make sure that your application is not having any inter dependencies other than this executable.
GoldestJava Is A Funny Language... Really!.gif)
Click on * and add to member reputation, if you find their advices/solutions effective.
- 01-18-2011, 10:27 AM #17
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
When the OS starts a process is attaches three streams to it: stdin, stdout and stderr. The default streams form a 'console' or 'terminal'. When no streams are supplied the OS uses the default Streams. The ProcessBuilder supplies those three Streams because the parent process must be able to read from the process and write to it; that's why no console starts up.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 01-19-2011, 03:23 AM #18
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
- 01-19-2011, 08:23 AM #19
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
Sure, just start it but you won't see its window because the Streams are supplied by your Java program. On Unix/Linux one can start a shell in 'interactive' mode by supplying a flag. I don't know if that feature exists in MS Windows. Consult the (online) manual for the cmd.exe program.
kind regards,
Jos
ps. or even nicer: write your own terminal program. It can be done without too many problems.When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 01-19-2011, 10:24 AM #20
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
Similar Threads
-
launching applet via jsp
By rafzio4 in forum New To JavaReplies: 2Last Post: 09-24-2010, 08:35 AM -
launching .rm file outside java
By nonboyx in forum Threads and SynchronizationReplies: 2Last Post: 09-28-2009, 07:40 PM -
Launching Eclipse Preferences from button
By sarcasteak in forum EclipseReplies: 3Last Post: 08-04-2009, 10:10 PM -
Launching applications without an IDE
By this_is_phil in forum New To JavaReplies: 6Last Post: 05-24-2008, 07:54 AM -
Launching Applet from a JSP page
By Java Tip in forum Java TipReplies: 0Last Post: 01-31-2008, 12:53 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks