Created
October 22, 2018 02:55
-
-
Save papadave66/ed3640b24dad7cb1b91181713e35ddfa to your computer and use it in GitHub Desktop.
a demo to read error by using java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.InputStream; | |
public class Main{ | |
public static void main(String[] args){ | |
try{ | |
new ProcessBuilder("gcc", "-o", "test.out", "test.c").start(); | |
ProcessBuilder process_builder = new ProcessBuilder("./test.out", ""); | |
Process run_process; | |
run_process = process_builder.start(); | |
InputStream subprocess_error = run_process.getErrorStream(); | |
byte[] a = subprocess_error.readAllBytes(); | |
System.out.print(new String(a)); | |
// for (int i = 0; i < subprocess_error.available(); i++){ | |
// System.out.print("" + subprocess_error.read()); | |
// } | |
}catch(Exception e){ | |
System.out.println("something is wrong"); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<unistd.h> | |
int main() | |
{ | |
write(1,"111111111---stdout", 18); | |
write(2,"222222222---stderr", 18); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment