Thread overview
pipeProcess output to hash string
Sep 09
Vino
Sep 09
user1234
Sep 09
evilrat
Sep 10
Vino
Sep 12
vino
Sep 12
user1234
September 09

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

September 09

On Saturday, 9 September 2023 at 15:44:44 UTC, 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

With a slightly modified command line that works on linux here :

import std.process, std.stdio;

auto test(in Redirect redirect=Redirect.stdout | Redirect.stderr) {
    import std.digest.crc;
    import std.stdio: writeln;

     auto result = std.process.pipeProcess(["whoami"], redirect);
     auto content = result.stdout.readln;
     auto hash = crc32Of(content);
     return hash;
}
void main() {
  writeln(test);
}

not sure why you append "/?" to the program name.

September 09

On Saturday, 9 September 2023 at 16:49:30 UTC, user1234 wrote:

>

not sure why you append "/?" to the program name.

Windows maybe? Try this.

auto result = std.process.pipeProcess(["whoami", "/?"], redirect);

September 10

On Saturday, 9 September 2023 at 16:49:30 UTC, user1234 wrote:

>

On Saturday, 9 September 2023 at 15:44:44 UTC, Vino wrote:

>

[...]

With a slightly modified command line that works on linux here :

import std.process, std.stdio;

auto test(in Redirect redirect=Redirect.stdout | Redirect.stderr) {
    import std.digest.crc;
    import std.stdio: writeln;

     auto result = std.process.pipeProcess(["whoami"], redirect);
     auto content = result.stdout.readln;
     auto hash = crc32Of(content);
     return hash;
}
void main() {
  writeln(test);
}

not sure why you append "/?" to the program name.

Thank you, got it working.

From,
Vino

September 12

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

September 12

On Monday, 11 September 2023 at 22:08:54 UTC, Christian Köstlin wrote:

>

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

This is just an example, and more over execute has only stdout, where as we need all stdin,stdout,stderr, in order to minimize the runtime of log running task we run the stdout and stderr in a separate thread, the difference is that for pipeproces we have to use wait to ensure that the child process is completed, where as for execute we do not need to use wait, as the process exist only after the completion.

From,
Vino.

September 12

On Monday, 11 September 2023 at 22:08:54 UTC, Christian Köstlin wrote:

>

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

I'll add that the way pipeProcess is overloaded does not help. One take the whole command line as a string the other each element as an array. Very easy to get it wrong.