digitalmars.D.learn - Basic question about stderr
- chaseratx (8/8) May 21 2016 I'm learning D and I have a basic question.
- Era Scarecrow (9/17) May 21 2016 // <= causes range violation, might use foreach instead
- chaseratx (6/26) May 21 2016 Thanks Era, but I am not trying to fix the range error. That was
- Era Scarecrow (12/17) May 21 2016 Ahh, I didn't realize you were intentionally trying to use the
- Era Scarecrow (6/12) May 21 2016 Well found a quick solution. gotta close the original handle
- chaseratx (2/14) May 21 2016 Oh, excellent! I will try that now. :)
- Mike Parker (4/21) May 21 2016 This should also work:
- chaseratx (6/23) May 21 2016 Ok, thanks for looking into it. It does seem like it should work
I'm learning D and I have a basic question. I'm trying to write stderr to a file using open() (rather than shell piping/redirection). It works for stdout but doesn't seem to work with stderr. http://pastebin.com/KgzR9wAF stdout is written to the file, but stderr is not and outputs to the shell. I'm not sure why. I Googled but couldn't find an answer. Any hints?
May 21 2016
On Saturday, 21 May 2016 at 21:21:31 UTC, chaseratx wrote:I'm learning D and I have a basic question. I'm trying to write stderr to a file using open() (rather than shell piping/redirection). It works for stdout but doesn't seem to work with stderr. http://pastebin.com/KgzR9wAF stdout is written to the file, but stderr is not and outputs to the shell. I'm not sure why. I Googled but couldn't find an answer. Any hints?// <= causes range violation, might use foreach instead while (i < numbers.length) { write(numbers[i], " "); stderr.write(numbers[i]*10); //force stderr, 10x to differentiate output with (stderr) { //also force stderr write(" "); }
May 21 2016
On Saturday, 21 May 2016 at 21:40:36 UTC, Era Scarecrow wrote:On Saturday, 21 May 2016 at 21:21:31 UTC, chaseratx wrote:Thanks Era, but I am not trying to fix the range error. That was put there intentionally to create stderr output. I'm trying to figure out how to get ALL stderr output directed to a file the same as if I had used a "2>error.log" redirect from the command line.I'm learning D and I have a basic question. I'm trying to write stderr to a file using open() (rather than shell piping/redirection). It works for stdout but doesn't seem to work with stderr. http://pastebin.com/KgzR9wAF stdout is written to the file, but stderr is not and outputs to the shell. I'm not sure why. I Googled but couldn't find an answer. Any hints?// <= causes range violation, might use foreach instead while (i < numbers.length) { write(numbers[i], " "); stderr.write(numbers[i]*10); //force stderr, 10x to differentiate output with (stderr) { //also force stderr write(" "); }
May 21 2016
On Saturday, 21 May 2016 at 21:47:20 UTC, chaseratx wrote:Thanks Era, but I am not trying to fix the range error. That was put there intentionally to create stderr output. I'm trying to figure out how to get ALL stderr output directed to a file the same as if I had used a "2>error.log" redirect from the command line.Ahh, I didn't realize you were intentionally trying to use the exception for the error output. I wonder, this sounds like a TLS (Thread Local Storage) issue where the local thread's stderr was updated but the global (shared?) one wasn't. https://dlang.org/phobos/std_stdio.html#.stderr The stderr is defined as "File stderr", not shared. I'm convinced TLS is the likely culprit. Unless you can affect the original instantiation it probably isn't going to work. I just tried using a static this() and it has a similar effect but doesn't affect stderr. :(
May 21 2016
On Saturday, 21 May 2016 at 21:54:43 UTC, Era Scarecrow wrote:On Saturday, 21 May 2016 at 21:47:20 UTC, chaseratx wrote:Thanks Era, but I am not trying to fix the range error. That was put there intentionally to create stderr output.I wonder, this sounds like a TLS (Thread Local Storage) issue where the local thread's stderr was updated but the global (shared?) one wasn't.Well found a quick solution. gotta close the original handle first! :) stderr.close(); stderr.open("error.log", "a"); stdout.open("output.log", "a");
May 21 2016
On Saturday, 21 May 2016 at 22:08:15 UTC, Era Scarecrow wrote:On Saturday, 21 May 2016 at 21:54:43 UTC, Era Scarecrow wrote:Oh, excellent! I will try that now. :)On Saturday, 21 May 2016 at 21:47:20 UTC, chaseratx wrote:Thanks Era, but I am not trying to fix the range error. That was put there intentionally to create stderr output.I wonder, this sounds like a TLS (Thread Local Storage) issue where the local thread's stderr was updated but the global (shared?) one wasn't.Well found a quick solution. gotta close the original handle first! :) stderr.close(); stderr.open("error.log", "a"); stdout.open("output.log", "a");
May 21 2016
On Saturday, 21 May 2016 at 22:11:30 UTC, chaseratx wrote:On Saturday, 21 May 2016 at 22:08:15 UTC, Era Scarecrow wrote:This should also work: stderr = File("error.log", "a"); stdout = File("output.log", "a");On Saturday, 21 May 2016 at 21:54:43 UTC, Era Scarecrow wrote:Oh, excellent! I will try that now. :)On Saturday, 21 May 2016 at 21:47:20 UTC, chaseratx wrote:Thanks Era, but I am not trying to fix the range error. That was put there intentionally to create stderr output.I wonder, this sounds like a TLS (Thread Local Storage) issue where the local thread's stderr was updated but the global (shared?) one wasn't.Well found a quick solution. gotta close the original handle first! :) stderr.close(); stderr.open("error.log", "a"); stdout.open("output.log", "a");
May 21 2016
On Saturday, 21 May 2016 at 21:54:43 UTC, Era Scarecrow wrote:On Saturday, 21 May 2016 at 21:47:20 UTC, chaseratx wrote:Ok, thanks for looking into it. It does seem like it should work (to me) since there is no apparent difference between stdout and stderr in the docs, and using open() works for stdout. Not something I could intuit. Appreciate the help.Thanks Era, but I am not trying to fix the range error. That was put there intentionally to create stderr output. I'm trying to figure out how to get ALL stderr output directed to a file the same as if I had used a "2>error.log" redirect from the command line.Ahh, I didn't realize you were intentionally trying to use the exception for the error output. I wonder, this sounds like a TLS (Thread Local Storage) issue where the local thread's stderr was updated but the global (shared?) one wasn't. https://dlang.org/phobos/std_stdio.html#.stderr The stderr is defined as "File stderr", not shared. I'm convinced TLS is the likely culprit. Unless you can affect the original instantiation it probably isn't going to work. I just tried using a static this() and it has a similar effect but doesn't affect stderr. :(
May 21 2016