www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - dub build output redirect

reply seany <seany uni-bonn.de> writes:
I have compiled a complex project via `dub build`.

I used both `-b release` and `-b debug`.

But i cant redirect the output (generated by `writeln`) to a file.

I call by : `./executable --param p1 > a`. But execution hangs 
immediately. If I do `./executable --param p1 ` no issue.

What am I doing wrong?

thank you.
Jun 08 2021
parent reply Steven Schveighoffer <schveiguy gmail.com> writes:
On 6/8/21 8:38 AM, seany wrote:
 I have compiled a complex project via `dub build`.
 
 I used both `-b release` and `-b debug`.
 
 But i cant redirect the output (generated by `writeln`) to a file.
 
 I call by : `./executable --param p1 > a`. But execution hangs 
 immediately. If I do `./executable --param p1 ` no issue.
 
 What am I doing wrong?
 
 thank you.
Are you expecting input as well as sending output? A common behavior difference between console streams and file streams (including in D) is that when the library detects it's sending to a console, it flushes buffered output after every newline. When it's sending to a file (or other stream type), it only sends output when the buffer is full (usually about 4k bytes). The hang sounds like it has buffered up its output ready to send, and then is waiting for input to continue. -Steve
Jun 08 2021
parent reply seany <seany uni-bonn.de> writes:
On Tuesday, 8 June 2021 at 13:51:10 UTC, Steven Schveighoffer 
wrote:
 On 6/8/21 8:38 AM, seany wrote:
 I have compiled a complex project via `dub build`.
 
 I used both `-b release` and `-b debug`.
 
 But i cant redirect the output (generated by `writeln`) to a 
 file.
 
 I call by : `./executable --param p1 > a`. But execution hangs 
 immediately. If I do `./executable --param p1 ` no issue.
 
 What am I doing wrong?
 
 thank you.
Are you expecting input as well as sending output? A common behavior difference between console streams and file streams (including in D) is that when the library detects it's sending to a console, it flushes buffered output after every newline. When it's sending to a file (or other stream type), it only sends output when the buffer is full (usually about 4k bytes). The hang sounds like it has buffered up its output ready to send, and then is waiting for input to continue. -Steve
Hi Thank you for pointing this out. Indeed, much later in the code, there is a `readln()`. But, the program needs to run 1-2 minutes, until it reaches that point - it is doing a complex AI calculation. However, for these 1-2 minutes, there is no output. Not via `tee`command, also not when i do a `tail -f a` (`a` is the logfile as in my last mail). I expect the output of these 1-2 minutes, until the `readln` point to be visible via either of these to methods. Is it still the same case as you describe?
Jun 08 2021
parent reply Steven Schveighoffer <schveiguy gmail.com> writes:
On 6/8/21 10:05 AM, seany wrote:
 
 Hi
 
 Thank you for pointing this out.
 
 Indeed, much later in the code, there is a `readln()`.
 But, the program needs to run 1-2 minutes, until it reaches that point - 
 it is doing a complex AI calculation.
 
 However, for these 1-2 minutes, there is no output. Not via 
 `tee`command, also not when i do a `tail -f a` (`a` is the logfile as in 
 my last mail). I expect  the output of these 1-2 minutes, until the 
 `readln` point to be visible via either of these to methods.
 
 Is it still the same case as you describe?
Yes, that is exactly the case. `tee` and `tail` commands are not considered a console. Insert a `stdout.flush;` every time you want more output to appear, and it should fix the issue. -Steve
Jun 08 2021
parent seany <seany uni-bonn.de> writes:
On Tuesday, 8 June 2021 at 14:15:47 UTC, Steven Schveighoffer 
wrote:
 On 6/8/21 10:05 AM, seany wrote:
 
 Hi
 
 Thank you for pointing this out.
 
 Indeed, much later in the code, there is a `readln()`.
 But, the program needs to run 1-2 minutes, until it reaches 
 that point - it is doing a complex AI calculation.
 
 However, for these 1-2 minutes, there is no output. Not via 
 `tee`command, also not when i do a `tail -f a` (`a` is the 
 logfile as in my last mail). I expect  the output of these 1-2 
 minutes, until the `readln` point to be visible via either of 
 these to methods.
 
 Is it still the same case as you describe?
Yes, that is exactly the case. `tee` and `tail` commands are not considered a console. Insert a `stdout.flush;` every time you want more output to appear, and it should fix the issue. -Steve
Ok, thank you. it works.
Jun 08 2021