How to get output of piped process?
Steven Schveighoffer
schveiguy at gmail.com
Thu Feb 18 17:27:48 UTC 2021
On 2/18/21 4:40 AM, frame wrote:
> On Thursday, 18 February 2021 at 06:04:13 UTC, Jedi wrote:
>
>>> Unfortunately, std.process wraps all the pipes in File structs, so
>>> you have almost no good mechanisms to properly read the data.
>>>
>> WTF?
It's just the way it is. Everything in Phobos is a C FILE * (wrapped in
a File). You need to use alternative i/o systems to get the information.
you can I believe get the file descriptor out of the File, which should
help with better mechanisms. Try `fileno` and `windowsHandle`.
>
> I'm wonder about this message. You can always use readln() and eof() on
> such kind of streams. byLine() is just not the best option here.
readln will block. eof doesn't tell you that there is no data in the
pipe, it just says whether the pipe has been closed.
What you need is non-blocking ways to check "does this pipe have more
output for me?" If you read the implementation of execute, it gets
around this by redirecting stderr to stdout (so you can wait on just one
pipe).
If you need them separated, then you need to do something more
asynchronous. And Phobos does not wrap that, you have to use OS primitives.
-Steve
More information about the Digitalmars-d-learn
mailing list