How to get output of piped process?

Danny Arends Danny.Arends at gmail.com
Wed Mar 3 20:32:49 UTC 2021


On Thursday, 25 February 2021 at 15:28:25 UTC, kdevel wrote:
> On Monday, 22 February 2021 at 13:23:40 UTC, Danny Arends wrote:
>> On Friday, 19 February 2021 at 15:39:25 UTC, kdevel wrote:
>
> [...]
>
>>> Fortunately the D runtime /does/ take care and it throws---if 
>>> the signal
>>> is ignored beforehand. I filed issue 21649.
>
> [...]
>
>> Perhaps a bit late,
>
> It's never too late.™ :-)
>
>> but this is how I deal with pipes and spawnShell.
>> Read one byte at a time from stdout and stderr:
>>
>> https://github.com/DannyArends/DaNode/blob/master/danode/process.d
>
> Is this immune to SIGPIPE and is this design able to serve 
> infinite
> streams?

No I have linked up a signal handler to just ignore sigpipe, the 
web server closes connections after not seeing a valid output 
from the script for 5min (e.g. no header)

> BTW: Why does run use spawnShell and not spawnProcess (would
> save one File object).

I tried different approaches, this one worked for me™ and I just 
went with it. I need the stdin (for the get/post/cookies) stdout 
(php/d/brainf*ck script output) and stderr for the error stream 
from he external script

>
> If the design is not intended to serve infinite streams I would
> suggest to open two temporary files "out" and "err", delete 
> them,
> and let the child process write stdout/stderr into those files.

I used to do that, but it generated a lot of temporary files, and 
I would need to parse in the files after the process is done to 
serve the output to the client. Using pipes is cleaner code wise, 
since I can just stream back the output to the client (e.g. in 
keepalive connections)

> IFAICS this avoid threads, sleep, pipe and reading with fgetc.




More information about the Digitalmars-d-learn mailing list