// this the c++ code for the hello.exe #include<iostream.h> #include<conio.h> int main() { cout<<"Hello world\n"; getch(); cout<<"i bypass eroor\n"; return 0; } // i need to run the hello.exe from the java program
package procs; import java.io.*; import java.lang.*; import java.util.*; /** * * @author prodesign */ public class Procs { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner scan = new Scanner(System.in); try { int exitVal; char c='a'; Process process = Runtime.getRuntime().exec(new String[]{"C:/hello.exe"}); OutputStream stdin = process.getOutputStream (); InputStream stderr = process.getErrorStream (); InputStream stdout = process.getInputStream (); BufferedReader reader = new BufferedReader (new InputStreamReader(stdout)); //PrintStream writer = new PrintStream(new BufferedOutputStream(stdin)); //BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin)); // i uses both printstream and Buffered writer System.out.println("lets start<<<<<<"); do { c=(char)reader.read(); System.out.print(c); }while(c!='\n'); //writer.Print(c); i uses both print //writer.write(c); and the writer writer.flush(); do { c=(char)reader.read(); System.out.print(c); }while(c!='\n'); exitVal=process.waitFor(); System.out.println("Exited with error code "+exitVal); }catch (Exception e) { e.printStackTrace(); } } }
exitVal=process.waitFor();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)