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 :
- I write the path of the link41b.exe
- I execute link41b.exe
- I wait until she excute this application and it give me a result .
- 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?