Skip to content

Instantly share code, notes, and snippets.

@papadave66
Created October 22, 2018 02:55
Show Gist options
  • Save papadave66/ed3640b24dad7cb1b91181713e35ddfa to your computer and use it in GitHub Desktop.
Save papadave66/ed3640b24dad7cb1b91181713e35ddfa to your computer and use it in GitHub Desktop.
a demo to read error by using java
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");
}
}
}
#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