Writing in the cmd after executing an app.exe from

2019-09-17 20:09发布

问题:

I want to execute a command in the cmd from java. I want to execute link41b.exe in cmd from java. Normally it work like that :

  1. I write the path of the link41b.exe
  2. I execute link41b.exe
  3. I wait until she excute this application and it give me a result .
  4. I write the sentence that I want to link it

For example: linkparser>""the sentence""

So to execute this command I have written this code.

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;

public class tistlink {

public static void main(String[] args) {

        Process child;
        String line;
        try {

        String command="cmd /c link41b.exe";
            child = Runtime.getRuntime().exec(command);
            child.waitFor();
             OutputStream out = child.getOutputStream();
             PrintStream printStream = new PrintStream(out);
             printStream.println(" the girl is beautifull");

             System.out.println(child.exitValue());

         BufferedReader input =new BufferedReader(new     
                     InputStreamReader(child.getInputStream()));          
          while((line = input.readLine()) != null)
         {System.out.println(line); }
        } catch (IOException e) {   
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }}

}

The method exitvalue() returns 1. But it didn't return the result.

What it is the problem of this code because it gave me any error?

标签: java windows cmd