我正在编写Java程序来捕获终端命令的输出。在"正常"条件,即我自己直接执行命令的终端,我可以看到以下结果:
但是,我的Java程序呈现的输出只捕获了其中的一小部分,请参见此处:
这是我所说的代码库:
import java.io.*;
class evmTest {
public static void main(String[] args) {
String evmResult = "";
String evmCommand = "evm --debug --code 7f00000000000000000000000000000000000000000000000000000000000000027f00000000000000000000000000000000000000000000000000000000000000027f00000000000000000000000000000000000000000000000000000000000000020101 run";
try {
Runtime r = Runtime.getRuntime();
Process p = r.exec(evmCommand);
BufferedReader in = new BufferedReader(new
InputStreamReader(p.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
evmResult += inputLine;
}
in.close();
} catch (IOException e) {
System.out.println(e);
}
}
}
到目前为止,我还无法确定为什么该代码只能发出微不足道的0x
。我发布了这个问题,希望有人能够帮助我找出导致此错误的原因。
答案 0 :(得分:-1)
这样做:
import java.io.*;
class evmTest {
public static void main(String[] args) {
String evmResult = "";
String evmCommand = "evm --debug --code 7f00000000000000000000000000000000000000000000000000000000000000027f00000000000000000000000000000000000000000000000000000000000000027f00000000000000000000000000000000000000000000000000000000000000020101 run";
try {
Runtime rt = Runtime.getRuntime();
String command = "evm --debug --code 7f00000000000000000000000000000000000000000000000000000000000000027f00000000000000000000000000000000000000000000000000000000000000027f00000000000000000000000000000000000000000000000000000000000000020101 run";
Process proc = rt.exec(command);
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(proc.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(proc.getErrorStream()));
// read the output from the command
System.out.println("Here is the standard output of the command:\n");
String s = null;
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
// read any errors from the attempted command
System.out.println("Here is the standard error of the command (if any):\n");
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}
} catch (IOException e) {
System.out.println(e);
}
}
}