# \[HOWTO\] Call a process and getting it's info?

**URL:** <https://discourse.julialang.org/t/howto-call-a-process-and-getting-its-info/42854>\
**Category:** New to Julia\
**Created:** [July 10, 2020, 4:36pm UTC](https://discourse.julialang.org/t/howto-call-a-process-and-getting-its-info/42854 "2020-07-10T16:36:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![phykos](https://avatars.discourse-cdn.com/v4/letter/p/c67d28/32.png) [@phykos](https://discourse.julialang.org/u/phykos)\
**Post date:** [July 10, 2020, 4:36pm UTC](https://discourse.julialang.org/t/howto-call-a-process-and-getting-its-info/42854/1 "2020-07-10T16:36:26Z")

</div>

I want to call, for example the process `ls -a`, and from that, I want it’s total time, user time, system time, cpu time, RAM used etc., like the `time` commands available in most shells, such as bash, zsh and so on.  
How can I do this?

---

<div class="post-metadata">

**Author:** ![recri](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/recri/32/5280_2.png) [@recri](https://discourse.julialang.org/u/recri)\
**Post date:** [July 10, 2020, 8:25pm UTC](https://discourse.julialang.org/t/howto-call-a-process-and-getting-its-info/42854/2 "2020-07-10T20:25:49Z")

</div>

`run(`time ls -a`)` will deliver the ls output and the time information to standard output. It’s calling the `/usr/bin/time` command on linux rather than using a shell builtin or a julia emulation.

`a = read(`time ls -a`, String)` will deliver the ls output as a `String`, but the time information - which is printed to stderr - still goes to julia’s standard output.

The `pipeline` function allows pipes and redirections, but I don’t see any way to do the equivalent of `time ls -a 2>&1` which would append the time information after the directory listing.

`a = read(pipeline(`time ls -a`; stderr="time.out"), String)` will deliver the output of `ls` as a `String` and redirect the time command output into a file, then `t = read("time.out", String)` will collect the output of the time command as a string.

The man page for `/usr/bin/time` has a wealth of formatting options.

---

<div class="post-metadata">

**Author:** ![phykos](https://avatars.discourse-cdn.com/v4/letter/p/c67d28/32.png) [@phykos](https://discourse.julialang.org/u/phykos)\
**Post date:** [July 11, 2020, 11:53am UTC](https://discourse.julialang.org/t/howto-call-a-process-and-getting-its-info/42854/3 "2020-07-11T11:53:45Z")

</div>

On ZSH `which time` says it’s a shell reserved keyword, with my simple which that I wrote for my IRB, returns `nil` (Ruby’s `nothing`).

Furthermore, `file /usr/bin/time` says: “/usr/bin/time: cannot open `/usr/bin/time’ (No such file or directory)”

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [July 11, 2020, 12:49pm UTC](https://discourse.julialang.org/t/howto-call-a-process-and-getting-its-info/42854/4 "2020-07-11T12:49:12Z")

</div>

Yes `time` is a shell builtin, but it’s also a program. It appears that it’s not installed on your system, but you can probably install it, for example with `apt install time` on Debian or Ubuntu.

---

<div class="post-metadata">

**Author:** ![recri](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/recri/32/5280_2.png) [@recri](https://discourse.julialang.org/u/recri)\
**Post date:** [July 11, 2020, 1:25pm UTC](https://discourse.julialang.org/t/howto-call-a-process-and-getting-its-info/42854/5 "2020-07-11T13:25:21Z")

</div>

Well, as @sijo suggests, you could install the time command.

Or you could use the zsh builtin function itself.

```julia
a = read(pipeline(`zsh -c 'time ls -a'`; stderr="time.out"), String)
t = read("time.out", String)

```

Or you could modify julia/base/process.jl, the library that implements `run(...)`, to incorporate a `time(...)` function into Julia.
