how to execute c++ exe from java

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Feb 2007
Posts: 2
Reputation: kaushalsahil09 is an unknown quantity at this point 
Solved Threads: 0
kaushalsahil09 kaushalsahil09 is offline Offline
Newbie Poster

how to execute c++ exe from java

 
0
  #1
Feb 2nd, 2007
please tell me how I can execute c++ program frm java

I had tried this one but it does`t work


/*import java.io.*;
public class exe1
{
public static void main(String[] arg)
{
try
{
Runtime rt = Runtime.getRuntime();
//int s=rt.availableProcessors();
Process prcs =rt.exec("inventry.exe");
InputStreamReader isr =new InputStreamReader(prcs.getInputStream());
BufferedReader br = new BufferedReader(isr);
String line;
while((line=br.readLine())!=null)
System.out.println(line);


}
catch(IOException ioe)
{
System.exit(0);
}

}
} */

thanks sahil
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 7
Reputation: rahulmenonr is an unknown quantity at this point 
Solved Threads: 0
rahulmenonr rahulmenonr is offline Offline
Newbie Poster

Re: how to execute c++ exe from java

 
0
  #2
Apr 3rd, 2007
Originally Posted by kaushalsahil09 View Post
please tell me how I can execute c++ program frm java

I had tried this one but it does`t work


/*import java.io.*;
public class exe1
{
public static void main(String[] arg)
{
try
{
Runtime rt = Runtime.getRuntime();
//int s=rt.availableProcessors();
Process prcs =rt.exec("inventry.exe");
InputStreamReader isr =new InputStreamReader(prcs.getInputStream());
BufferedReader br = new BufferedReader(isr);
String line;
while((line=br.readLine())!=null)
System.out.println(line);


}
catch(IOException ioe)
{
System.exit(0);
}

}
} */

thanks sahil




hi buddy


you add this line also and try i am not sure

Runtime rt = Runtime.getRuntime();
Process prcs =rt.exec("inventry.exe");



Thread.sleep(3000);



you check wether the ex is in same folder or not


actualy your code is correct try this...
regards
rahulmenonr
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 539
Reputation: thekashyap will become famous soon enough thekashyap will become famous soon enough 
Solved Threads: 50
thekashyap's Avatar
thekashyap thekashyap is offline Offline
Posting Pro

Re: how to execute c++ exe from java

 
0
  #3
Apr 3rd, 2007
Originally Posted by rahulmenonr View Post
Thread.sleep(3000);
Using waitFor() would be a better idea..
  1. prcs.waitFor();

@kaushalsahil09 - Some more description of error than "I had tried this one but it does`t work" would help.
Last edited by thekashyap; Apr 3rd, 2007 at 6:09 am.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 1
Reputation: zanku is an unknown quantity at this point 
Solved Threads: 0
zanku zanku is offline Offline
Newbie Poster

Re: how to execute c++ exe from java

 
0
  #4
Apr 5th, 2007
Hi,

Plz. try it.

class test {
public static void main(String a[]) {
try {
Runtime rt=Runtime.getRuntime();
Process pr=rt.exec("inventry.exe");
}catch(Exception e) {
System.out.println("Error in main() : " +e);
}
}
}

NOTE: This inventry.exe should be in the same folder that of test.class's directory, otherwise above code won't work.
Last edited by zanku; Apr 5th, 2007 at 4:04 am. Reason: forget to add imp note.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 2
Reputation: kaushalsahil09 is an unknown quantity at this point 
Solved Threads: 0
kaushalsahil09 kaushalsahil09 is offline Offline
Newbie Poster

Re: how to execute c++ exe from java

 
0
  #5
Apr 6th, 2007
Originally Posted by rahulmenonr View Post
hi buddy


you add this line also and try i am not sure

Runtime rt = Runtime.getRuntime();
Process prcs =rt.exec("inventry.exe");



Thread.sleep(3000);



you check wether the ex is in same folder or not


actualy your code is correct try this...
regards
rahulmenonr
Thanks Dear for your help Its really very nice of u.

Actuallly my problem is not ye solved. It gives an error . Error while setting up the enviromental variables. If u want any kind of help let me know If I am able to help u I can.

Thanks
Sahil kaushal
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 3
Reputation: daninator09 is an unknown quantity at this point 
Solved Threads: 0
daninator09 daninator09 is offline Offline
Newbie Poster

Re: how to execute c++ exe from java

 
0
  #6
Apr 7th, 2007
The import statement at the top does not need to be commented. (Take out the /* and *)
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 539
Reputation: thekashyap will become famous soon enough thekashyap will become famous soon enough 
Solved Threads: 50
thekashyap's Avatar
thekashyap thekashyap is offline Offline
Posting Pro

Re: how to execute c++ exe from java

 
0
  #7
Apr 9th, 2007
Does the msg come from inventory.exe or your java program?

Post what you see on teh UI...
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 539
Reputation: thekashyap will become famous soon enough thekashyap will become famous soon enough 
Solved Threads: 50
thekashyap's Avatar
thekashyap thekashyap is offline Offline
Posting Pro

Re: how to execute c++ exe from java

 
0
  #8
Apr 9th, 2007
>> The import statement at the top does not need to be commented. (Take out the /* and *)
If some import is missing/wrong it'll give a compilation error not runtime..
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 3
Reputation: daninator09 is an unknown quantity at this point 
Solved Threads: 0
daninator09 daninator09 is offline Offline
Newbie Poster

Re: how to execute c++ exe from java

 
0
  #9
Apr 9th, 2007
Originally Posted by thekashyap View Post
>> The import statement at the top does not need to be commented. (Take out the /* and *)
If some import is missing/wrong it'll give a compilation error not runtime..
We don't know it's a runtime error. Also, I'm not sure what error you're trying to describe but is it anything like this?
http://forums.java.net/jive/thread.jspa?messageID=66696
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC