How do I get the output of the time bash command?
Arafel
er.krali at gmail.com
Wed Jan 27 09:58:18 UTC 2021
On 27/1/21 10:35, Anthony wrote:
>
> I'm trying to read the timed output of a pipeShell command but it only
> results in empty output.
>
> Does anyone know why this is?
>
>
> ```
> auto p = pipeShell("time ls");
>
> foreach(str; p.stdout.byLine) {
> writefln("%s",str);
> }
> ```
I'm not sure why you get an empty output, you should get at least the
`ls` output unless it's an empty directory (or one with only "dot" files).
However, in any case `time` returns the timing information through
`stderr`, not `stdout`[1]. You can try [2,3] (untested):
```
auto p = pipeShell("time ls", Redirect.stderrToStdout);
```
Best,
A.
[1]: https://linux.die.net/man/1/time
[2]: https://dlang.org/library/std/process/pipe_shell.html
[3]: https://dlang.org/library/std/process/redirect.html
More information about the Digitalmars-d-learn
mailing list