'Why floating point error message is not printing on stderr?
I am running c language code using a java application using java.lang.ProcessBuilder
. If any output and error generated by this c language code, I am able to read those via process.getInputStream()
and process.getErrorStream()
. But in some cases (when exit code = 136 or 139) like if the code execution failed due to floating point error
, I am not getting any error in process's error stream.
So, I tried to run my c language code directly on shell and redirected stderr and stdout to seperate files.
Code.c
#include<stdio.h>
int main() {
int x = 1/0;
return 0;
}
Command I am running:
# gcc Code.c -o Code.out -std=c99
# ./Code.out 2>err.log 1>out.log
Floating point exception (core dumped)
As you can see above error is printing on shell only but not redirecting to err.log
. Also, nothing is there in err.log. My question is why this is not printing in stderr stream? As per my understanding if it is not printing in stderr I will not be able to read it via process.getErrorStream. Whatever the error message generated by code execution, I wanted to show it to end user.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|