| | |
how to execute c++ exe from java
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Feb 2007
Posts: 2
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Apr 2007
Posts: 7
Reputation:
Solved Threads: 0
•
•
•
•
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
Using waitFor() would be a better idea..
@kaushalsahil09 - Some more description of error than "I had tried this one but it does`t work" would help.
Java Syntax (Toggle Plain Text)
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.
•
•
Join Date: Apr 2007
Posts: 1
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Feb 2007
Posts: 2
Reputation:
Solved Threads: 0
•
•
•
•
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
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
•
•
Join Date: Apr 2007
Posts: 3
Reputation:
Solved Threads: 0
•
•
•
•
>> 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..
http://forums.java.net/jive/thread.jspa?messageID=66696
![]() |
Similar Threads
- How to run a *.exe file in Java (Java)
- How to run external .exe programs from java (Java)
- how to execute an *.exe file in a c-program? (C)
- How to make .exe file for my java prg (Java)
- Stupid question about java.exe (Java)
- How to create an exe for a Java application (Java)
- How to execute .exe file from the perl script (Perl)
Other Threads in the Java Forum
- Previous Thread: i am trying to run this code pls help :(
- Next Thread: eclipse or netbeans
| Thread Tools | Search this Thread |
Tag cloud for Java
addressbook android api apple applet application arguments array arrays automation binary bluetooth button calculator chat class classes client code columns component converter database draw eclipse error errors event exception file fractal ftp game givemetehcodez graphics gridlayout gui helpwithhomework html ide image inetaddress input integer j2me japplet java javaprojects jme jmf jni jpanel julia link linux list loop map method methods midlethttpconnection mobile netbeans newbie number objects openjavafx oracle php print problem program programming project projects recursion rim scanner screen server set signing size smart sms socket sort sql storm string support swing test threads time tree unlimited variablebinding webservices windows





