# Some basic question about the run() command

**URL:** <https://discourse.julialang.org/t/some-basic-question-about-the-run-command/12685>\
**Category:** General Usage\
**Tags:** question\
**Created:** [July 27, 2018, 12:53pm UTC](https://discourse.julialang.org/t/some-basic-question-about-the-run-command/12685 "2018-07-27T12:53:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![oniter](https://avatars.discourse-cdn.com/v4/letter/o/df705f/32.png) [@oniter](https://discourse.julialang.org/u/oniter)\
**Post date:** [July 27, 2018, 12:53pm UTC](https://discourse.julialang.org/t/some-basic-question-about-the-run-command/12685/1 "2018-07-27T12:53:45Z")

</div>

Questions:

1. Solved! Is it possible to run an external cmd in background?

> run(`sleep 10`)

works, but not

> run(`sleep 10 \&`)

1. In my docu run() is shown as

> run(command, args…)  
> Run a command object, constructed with backticks. Throws an error if anything goes wrong, including the process exiting with a non-zero status.

How to use the comma separated syntax?

> cmd = `kill`  
> run(cmd,12452 5467)

does not work.

1. Solved! How to pass arguments correct over?

If I like to stop several processes

> run(`kill 12452 5467`)

works fine. But if I generate a string of pids and try

> string = “12452 5467”  
> run(`kill $string`)

is not working. Although if I pass Integers over

> s1 = 12452  
> s2 = 5467  
> run(`kill $s1 $s2`)

it works. So how create an object which contains several integers and is accepted as argument?  
Ah, try a tuple

> stuple = tuple(12452,5467)

this works.

1. Solved! If an external cmd fails and exit with error code 1 is

> try  
> run()  
> catch

the only possibility to react on it? Or how else? Or how can I get back an empty string result?

Thx for any hints. Your help is very welcome as always.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [July 27, 2018, 1:08pm UTC](https://discourse.julialang.org/t/some-basic-question-about-the-run-command/12685/2 "2018-07-27T13:08:12Z")

</div>

Look at the output:

```julia
julia> string = "12452 5467"
"12452 5467"

julia> `kill $string`
`kill '12452 5467'`

julia> s1 = 12452; s2 = 5467;

julia> `kill $s1 $s2`
`kill 12452 5467`

```

> [@oniter](#):
>
> the only possibility to react on it?

Use `success`

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [July 28, 2018, 2:10am UTC](https://discourse.julialang.org/t/some-basic-question-about-the-run-command/12685/3 "2018-07-28T02:10:58Z")

</div>

> [@oniter](#):
>
> Is it possible to run an external cmd in background?

In Julia 0.7:

```jl
run(`sleep 10`, wait=false)

```

In Julia 0.6 it is spelled `spawn(`sleep 10`)`. You can wait on the result with `wait` if you want. You can also run commands in asynchronous tasks (green threads) with `@async`. Julia has good support for asynchronous I/O of all kinds.

---

<div class="post-metadata">

**Author:** ![oniter](https://avatars.discourse-cdn.com/v4/letter/o/df705f/32.png) [@oniter](https://discourse.julialang.org/u/oniter)\
**Post date:** [July 30, 2018, 9:14am UTC](https://discourse.julialang.org/t/some-basic-question-about-the-run-command/12685/4 "2018-07-30T09:14:30Z")

</div>

Thx for answering!

Over the spawn() function I found ignorestatus() which can be a solution too for question nr 4.

Therefore only question 2. remains open 😉

---

<div class="post-metadata">

**Author:** ![oniter](https://avatars.discourse-cdn.com/v4/letter/o/df705f/32.png) [@oniter](https://discourse.julialang.org/u/oniter)\
**Post date:** [August 5, 2018, 4:26am UTC](https://discourse.julialang.org/t/some-basic-question-about-the-run-command/12685/5 "2018-08-05T04:26:36Z")

</div>

Can someone explain the run syntax found in the Docs under

[https://docs.julialang.org/en/stable/stdlib/base/#Base.run](https://docs.julialang.org/en/stable/stdlib/base/#Base.run)

with an example showing that syntax. Sorry, but I maybe misunderstand it.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [August 5, 2018, 4:37pm UTC](https://discourse.julialang.org/t/some-basic-question-about-the-run-command/12685/6 "2018-08-05T16:37:21Z")

</div>

See [https://docs.julialang.org/en/stable/manual/running-external-programs/](https://docs.julialang.org/en/stable/manual/running-external-programs/)

The older blog post [Put This In Your Pipe](https://julialang.org/blog/2013/04/put-this-in-your-pipe) is still helpful though some of the syntax has changed slightly and [Shelling Out Sucks](https://julialang.org/blog/2012/03/shelling-out-sucks) is good to read for the for rationale behind Julia’s approach.
