我想在java的cmd中执行命令。我想从java执行cmd中的link41b.exe。通常情况就是这样:
例如:linkparser>""the sentence""
因此,为了执行此命令,我编写了此代码。
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();
}}
}
方法exitvalue()返回1.但它没有返回结果。
这段代码的问题是什么,因为它给了我任何错误?