pipeProcess output to hash string

Christian Köstlin christian.koestlin at gmail.com
Mon Sep 11 22:08:54 UTC 2023


On 09.09.23 17:44, Vino wrote:
> Hi All,
> 
>    Request your help on how to convert the output of 
> std.process.pipeProcess to hash string
> 
> ```
> 
> auto test(in Redirect redirect=Redirect.stdout | Redirect.stderr) {
>      import std.process;
>      import std.digest.crc;
>      import std.stdio: writeln;
> 
>       result = std.process.pipeProcess("whoami" ~ "/?", redirect);
>       auto content = result.stdout.readln;
>       auto hash = crc32Of(content);
>       return hash;
> }
> void main() {
>    writeln(test);
> }
> ```
> 
> Output: All writes the below.
> ```
> [0, 0, 0, 0]
> ```
> 
> Required: Read the completed output and convert it to a single hash string.
> 
> From,
> Vino.B
Good that you could solve your problem already.

Just three remarks:

First I would recommend to use `std.process : execute` instead of
`pipeProcess` in this usecase, as this will wait properly for the 
process to exit and it also will collect its output.

Second its always good to test the exit status of the process ... just 
in case.

Third I would not look at `stderr` too much .. well behaved commandline 
tools should not put data for machines there.

Kind regards,
Christian


More information about the Digitalmars-d-learn mailing list