-1

So I know that logging compilation errors can be done as follows in the terminal

gcc -o objectname filename.c 2>'compilation_error_log.txt'

I get some memory error while executing the code and want to log that as well. I tried the same approach

./objectname 2>'Execution_error_log.txt'

but it's not working. Can someone tell me where the memory errors get stored so I can log them? My error and output looks somewhat like this

./objectname arg
Expected Output.
*** Error in `./objectname': double free or corruption (!prev): 0x089d1008 ***
Aborted (core dumped)

I wanna log the expected output and the error messages

Mathews_M_J
  • 457
  • 4
  • 15
  • Look at this post: http://stackoverflow.com/questions/818255/in-the-shell-what-is-21 – Amadeus Sep 26 '14 at 02:33
  • i tried that. But it's not working. I have to give an argument while calling the object. Should have mentioned that.. – Mathews_M_J Sep 26 '14 at 02:54
  • Yup did that too. Didn't work :| Is the error a stderror or is it some other kind? – Mathews_M_J Sep 26 '14 at 03:08
  • So I am thinking now that it's not a stderror. Programs get aborted because of the SIGABRT signal as far as I understand. So this method shouldn't work. – Mathews_M_J Sep 26 '14 at 03:25
  • What kind of execution errors do you have? The `Aborted (core dumped)` message is given by your shell, not by your program! – Basile Starynkevitch Sep 27 '14 at 05:41
  • @BasileStarynkevitch: Ya I figured that out. Any idea how I could log that directly from shell? I ended up just copy pasting the whole thing from shell. – Mathews_M_J Sep 28 '14 at 19:13
  • Perhaps consider using [script(1)](http://man7.org/linux/man-pages/man1/script.1.html) command. I can't guess why you need to log all this. Consider editing your question to explain better. – Basile Starynkevitch Sep 28 '14 at 19:20
  • I wanna close this question. Like you said there's no particular point to this. I just wanted to log all errors I get for an assignment. I managed it anyways. – Mathews_M_J Sep 28 '14 at 19:36

2 Answers2

1

By default glibc error messaging is being written to /dev/tty, which isn't redirected to anywhere.

You can request messages in stderr by setting environment variable LIBC_FATAL_STDERR_ to 1. After that, you can 2> log.file.

Default behaviour is safe workaround when your application already closed stderr (or file descriptor 2), and fatal error happened after that.

keltar
  • 17,711
  • 2
  • 37
  • 42
0

Executing ./objectname arg 1 > compilation_error_log.txt 2>&1 in ash should work. Basically you have to provide the redirection to a file and then redirect the error stream to the stdin file descriptor.

  • 3
    That is the correct answer for redirecting to the compilation log. However, if you are going to post it as an **answer** as opposed to a **comment**, you need to explain your answer and provide background to educate the poster why this is the correct answer. Otherwise, even though it is correct, you will receive downvotes for providing a low-quality answer. – David C. Rankin Sep 26 '14 at 05:31
  • Please see if the information i have provided is sufficient. – user1525888 Sep 27 '14 at 03:37