943,683 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 103325
  • Java RSS
Jul 2nd, 2004
0

How to run external .exe programs from java

Expand Post »
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
Similar Threads
Reputation Points: 25
Solved Threads: 10
Practically a Master Poster
freesoft_2000 is offline Offline
623 posts
since Jun 2004
Jul 2nd, 2004
2

Re: How to run external .exe programs from java

the code goes like this:
Java Syntax (Toggle Plain Text)
  1. try
  2. {
  3. Runtime rt = Rintime.getRuntime() ;
  4. Process p = rt.exec("Program.exe") ;
  5. InputStream in = p.getInputStream() ;
  6. OutputStream out = p.getOutputStream ();
  7. InputSream err = p,getErrorStram() ;
  8.  
  9. //do whatever you want
  10. //some more code
  11.  
  12. p.destroy() ;
  13. }catch(Exception exc){/*handle exception*/}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
BlackDeath is offline Offline
4 posts
since Jul 2004
Jul 15th, 2004
0

Re: How to run external .exe programs from java

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:
Team Colleague
Reputation Points: 45
Solved Threads: 56
Unauthenticated Liar
nanosani is offline Offline
1,767 posts
since Jul 2004
Aug 28th, 2004
0

Re: How to run external .exe programs from java

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
Last edited by alc6379; Oct 23rd, 2004 at 4:30 am. Reason: removed email address
Reputation Points: 25
Solved Threads: 10
Practically a Master Poster
freesoft_2000 is offline Offline
623 posts
since Jun 2004
Aug 29th, 2004
0

Re: How to run external .exe programs from java

Read about the dynamic class loader

http://java.sun.com/j2se/1.4.2/docs...lassLoader.html
Team Colleague
Reputation Points: 45
Solved Threads: 56
Unauthenticated Liar
nanosani is offline Offline
1,767 posts
since Jul 2004
Oct 19th, 2004
0

Re: How to run external .exe programs from java

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...

Java Syntax (Toggle Plain Text)
  1. try
  2. {
  3. Runtime rt = Runtime.getRuntime();
  4. Process p = rt.exec("vbex.exe");
  5. InputStream in = p.getInputStream();
  6. OutputStream out = p.getOutputStream();
  7. InputStream err = p.getErrorStream();
  8.  
  9. p.destroy() ;
  10. }catch(Exception exc){/*handle exception*/}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ozzytx is offline Offline
1 posts
since Oct 2004
Oct 19th, 2004
0

Re: How to run external .exe programs from java

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
Reputation Points: 25
Solved Threads: 10
Practically a Master Poster
freesoft_2000 is offline Offline
623 posts
since Jun 2004
Jun 16th, 2008
0

Re: How to run external .exe programs from java

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
subroto1486 is offline Offline
3 posts
since Jun 2008
Apr 8th, 2011
-1
Re: How to run external .exe programs from java
Hi,

The following example shows opening a notepad using java application.

[url removed]
Last edited by Ezzaral; Apr 8th, 2011 at 1:22 pm. Reason: Snipped url. Promotion is not allowed here.
Reputation Points: 7
Solved Threads: 0
Newbie Poster
tsmc is offline Offline
2 posts
since Apr 2011
Apr 8th, 2011
0
Re: How to run external .exe programs from java
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-tip...ssbuilder.html
Last edited by JamesCherrill; Apr 8th, 2011 at 7:34 am.
Featured Poster
Reputation Points: 1907
Solved Threads: 950
Posting Expert
JamesCherrill is offline Offline
5,767 posts
since Apr 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in Java Forum Timeline: GUI help needed
Next Thread in Java Forum Timeline: Text File to ArrayList for JTextArea??





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC