请在下面的java代码中澄清问题

请在下面的java代码中澄清问题

本文介绍了请在下面的java代码中澄清问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  import java.lang.Process;
  import java.io.*;
  import java.io.InputStream;
  import java.io.IOException;
  public class prgms{
  public static void main(String[] args) {
    try {
      // Execute a command without arguments
      String command = "java JavaSimpleDateFormatExample";
      Process child = Runtime.getRuntime().exec(command);

      // Execute a command with an argument
      // command = "java JavaStringBufferAppendExample";
     //child = Runtime.getRuntime().exec(command);
    } catch (IOException e) {
    }
    InputStream in = child.getInputStream();
    int c;
    while ((c = in.read()) != -1) {
        process((char)c);
    }
    in.close();
  }
}

我是这样修改的...但是出现如下错误,

I have modified this way... but the following error occurs,

prgms.java:17: cannot find symbol
symbol  : variable child
location: class prgms
InputStream in = child.getInputStream();
                 ^
prgms.java:20: cannot find symbol
symbol  : method process(char)
location: class prgms
        process((char)c);
        ^
2 errors

推荐答案

您确实忽略了 stdoutstderrProcessRuntime#exec().

You're indeed ignoring the stdout and stderr streams of the Process returned by Runtime#exec().

这将是一个很长的故事,所以这里只是一个链接:当 Runtime.exec 不会.阅读所有四页.

This is going to be a long story, so here's just a link: When Runtime.exec won't. Read all the four pages.

这篇关于请在下面的java代码中澄清问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 19:08