- using java native api
- calling the c++ program as a process
import java.io.InputStream;
import java.io.OutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
class cpp_to_java {
private static void prnt()
{
try
{
String[] prg = new String[3];
prg[0] = new String("C:\\Documents and Settings\\cigdem.METU-GR0VQRPB9H\\My Documents\\Visual Studio 2005\\Projects\\deneme\\debug\\deneme.exe " );
prg[1] = new String("C:\\a.png");
prg[2] = new String("C:\\b.png");
Process p = Runtime.getRuntime().exec( prg) ;
//"C:\\Documents and Settings\\cigdem.METU-GR0VQRPB9H\\My Documents\\Visual Studio 2005\\Projects\\deneme\\debug\\deneme.exe " + "C:\\a.png" + " C:\\b.png"
//do whatever you want
//some more code
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
//System.out.println("Here is the standard output of the command:\n");
String s="";
int count=0;
String result="";
p.waitFor();
while((s=stdInput.readLine()) !=null){
count++;
result = result+s+"\n";
//System.out.println("result:"+count+": "+result);
}
System.out.println(result);
}catch(Exception exc){/*handle exception*/}
}
private static boolean procDone(Process p) {
try {
int v = p.exitValue();
return true;
}
catch(IllegalThreadStateException e) {
return false;
}
}
No comments:
Post a Comment