1,105,169 Community Members

How to run external .exe programs from java

Member Avatar
freesoft_2000
Practically a Master Poster
623 posts since Jun 2004
Reputation Points: 9 [?]
Q&As Helped to Solve: 11 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi everyone,

  Could some one please tell me or show me the entire codings of how to run external .exe programs in java. I want to do this because i have a lot c/vb programs that i want to run in my java program.

Thank You

Yours Sincerely

Richard West

Member Avatar
BlackDeath
Newbie Poster
4 posts since Jul 2004
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
2
 

the code goes like this:

try
{
 Runtime rt = Rintime.getRuntime() ;
 Process p = rt.exec("Program.exe") ;
 InputStream in = p.getInputStream() ;
 OutputStream out = p.getOutputStream ();
 InputSream err = p,getErrorStram() ;
 
//do whatever you want
 //some more code
 
 p.destroy() ;
}catch(Exception exc){/*handle exception*/}
Member Avatar
nanosani
Technize.net addict
1,764 posts since Jul 2004
Reputation Points: 20 [?]
Q&As Helped to Solve: 58 [?]
Skill Endorsements: 1 [?]
Team Colleague
 
0
 

try out this code ... it will not be platform independent ....
Process p = Runtime.getRuntime().exec("c:\myprogram.exe");

I dont have the time to test it .... if you succeed please tell me too.
:eek:

Member Avatar
freesoft_2000
Practically a Master Poster
623 posts since Jun 2004
Reputation Points: 9 [?]
Q&As Helped to Solve: 11 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi everyone,
The above codes only seem to run external .exe programs but what if i want to run external jar programs. Could someone show me or e-mail me the codings of how to do this the right way.


Thank You

Yours Sincerely

Richard West

Member Avatar
nanosani
Technize.net addict
1,764 posts since Jul 2004
Reputation Points: 20 [?]
Q&As Helped to Solve: 58 [?]
Skill Endorsements: 1 [?]
Team Colleague
 
0
 

Read about the dynamic class loader

http://java.sun.com/j2se/1.4.2/docs...lassLoader.html

Member Avatar
ozzytx
Newbie Poster
1 post since Oct 2004
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

i'm using the code from above to try to run a program and here's my problem... when i call an exe that i wrote in VB, the program runs fine. if i call a c or c++ program the program loads into memory (i see it in the processes tab) but the console doesn't open up with the program in it.
here's the code i have right now for it...

try
   {
    Runtime rt = Runtime.getRuntime();
    Process p = rt.exec("vbex.exe");
    InputStream in = p.getInputStream();
    OutputStream out = p.getOutputStream();
    InputStream err = p.getErrorStream();

    p.destroy() ;
    }catch(Exception exc){/*handle exception*/}
Member Avatar
freesoft_2000
Practically a Master Poster
623 posts since Jun 2004
Reputation Points: 9 [?]
Q&As Helped to Solve: 11 [?]
Skill Endorsements: 0 [?]
 
0
 

hi everyone,

              Do this instead



void run ()
{
try
{
Runtime rt = Runtime.getRuntime();
Process p = rt.exec("vbex.exe");
}

catch(Exception e)
{

}

}

I hope this helps you

Richard West

Member Avatar
subroto1486
Newbie Poster
3 posts since Jun 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

HI EVERYBODY,
I have a question regarding this i used this to call exe application but it is opening independently, but what if i want to run that particular exe in the frame itsself like an JInternal Frame..

Please help me regaridng this..

Thanks in advance..

Subroto Bhattacharjee

Member Avatar
tsmc
Newbie Poster
2 posts since Apr 2011
Reputation Points: -3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
-1
 

Hi,

The following example shows opening a notepad using java application.

Member Avatar
JamesCherrill
... trying to help
10,362 posts since Apr 2008
Reputation Points: 2,081 [?]
Q&As Helped to Solve: 1,749 [?]
Skill Endorsements: 47 [?]
Moderator
Featured
 
0
 

There are a load of answers in this 2004 zombie thread using Runtime.exec to run an external process, but this was superseded in Java 5 (JDK 1.5) with ProcessBuilder, which is now preferred to Runtime.exec
http://www.java-tips.org/java-se-tips/java.util/from-runtime.exec-to-processbuilder.html

Member Avatar
manish.mehta
Newbie Poster
3 posts since Jul 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

How to run external .exe programs from java in remote machine?

Hi,

I want to run a batch file in a remote machine using JAVA. Could anyone advise, how this is possible in JAVA code.

Reagrds
Manish

Member Avatar
stultuske
Posting Expert
5,290 posts since Jan 2007
Reputation Points: 935 [?]
Q&As Helped to Solve: 774 [?]
Skill Endorsements: 35 [?]
Featured
 
0
 

first of all, you could have figured out that this thread is 8 years old, and has been revived way to many times already. secondly, you could 've read the answers already given.

also, you might want to provide some more information.
are we talking a complete separate system? do you have a "client" app on the remote machine, can you access the remote machine, ... ?

Member Avatar
manish.mehta
Newbie Poster
3 posts since Jul 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Yes, i saw that, but i thought my problem is something similar to it. hence i posted here.

Actually, i am using Selenium Grid and running my test cases on remote machine. And i am also using Screen recorder to record video for my test. When i start Screen recorder, it only starts in the hub machine (my machine). So i thought to run the Screen recorder on remote machine by running a batch file using my Selenium Java code.

Member Avatar
JamesCherrill
... trying to help
10,362 posts since Apr 2008
Reputation Points: 2,081 [?]
Q&As Helped to Solve: 1,749 [?]
Skill Endorsements: 47 [?]
Moderator
Featured
 
0
 

DaniWeb Member Rules include:
"Do not hijack old threads by posting a new question as a reply to an old one"
http://www.daniweb.com/community/rules
Please start your own new thread for your question

Start New Discussion
Tags Related to this Article