Код: Выделить всё
#include
#include
#include
#include
int main() {
printf("Hello world\n");
fprintf(stderr, "Some error\n");
free((void*)1);
}
Код: Выделить всё
./a.out
Hello world
Some error
a.out(8435,0x2004a8f40) malloc: *** error for object 0x1: pointer being freed was not allocated
a.out(8435,0x2004a8f40) malloc: *** set a breakpoint in malloc_error_break to debug
zsh: abort ./a.out
Когда я пытаюсь выполнить ее из программы Java, я получаю выходные данные «Hello world» и «Некоторая ошибка», но не остальные строки содержат «malloc». Вот моя Java-программа:
Код: Выделить всё
import java.io.*;
public class Test {
public static void main(String... args) throws Exception {
runProcess(new File("a.out").getAbsolutePath());
}
public static void runProcess(String... command) throws Exception {
Process process = new ProcessBuilder(command).start();
Thread outThread = new Thread(() -> {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
});
outThread.start();
Thread outThread2 = new Thread(() -> {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getErrorStream()))) {
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
});
outThread2.start();
outThread.join();
outThread2.join();
int exitCode = process.waitFor();
System.out.println("Exit code: " + exitCode);
}
}
Код: Выделить всё
java Test
Some error
Hello world
Exit code: 134
Подробнее здесь: https://stackoverflow.com/questions/792 ... h-code-134
Мобильная версия