# Running External Program - getting the programs results not just the stdout

**URL:** <https://discourse.julialang.org/t/running-external-program-getting-the-programs-results-not-just-the-stdout/27499>\
**Category:** General Usage\
**Created:** [August 13, 2019, 2:09pm UTC](https://discourse.julialang.org/t/running-external-program-getting-the-programs-results-not-just-the-stdout/27499 "2019-08-13T14:09:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![timmm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/timmm/32/6760_2.png) [@timmm](https://discourse.julialang.org/u/timmm)\
**Post date:** [August 13, 2019, 2:09pm UTC](https://discourse.julialang.org/t/running-external-program-getting-the-programs-results-not-just-the-stdout/27499/1 "2019-08-13T14:09:10Z")

</div>

Hi,

I have managed to confuse myself but I am sure there is a simple answer.  
I have a c++ script I can call this in the terminal with:

```julia
./script $InputFile > $OutputFilePathAndName

```

With the terminal printing the stdout but also saving the c++ programs results to the file described in OutputFilePathAndName  
In Julia if I write something like:

```julia
TerminalLine="./script $InputFile > $OutputFilePathAndName"
TerminalLine=split("$TerminalLine")
run(`$TerminalLine`);

```

The file OutputFilePathAndName never writes? In a simple terminal this writes correctly but not using Julia ‘run’ or Julias shell.  
In windows I got around this using:

```julia
TerminalLine="./script $InputFile > $OutputFilePathAndName"
TerminalLine=split("powershell $TerminalLine")
run(`$TerminalLine`);

```

i.e. calling powershell as a subprocess.  
Any ideas what I need to do in Linux?

Cheers,  
Tim

---

<div class="post-metadata">

**Author:** ![Karajan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/karajan/32/8545_2.png) [@Karajan](https://discourse.julialang.org/u/Karajan)\
**Post date:** [August 13, 2019, 2:20pm UTC](https://discourse.julialang.org/t/running-external-program-getting-the-programs-results-not-just-the-stdout/27499/2 "2019-08-13T14:20:46Z")

</div>

I think [this](https://docs.julialang.org/en/v1/manual/running-external-programs/#Pipelines-1) might be right for you:

```julia
pipeline(`do_work`, stdout=pipeline(`sort`, "out.txt"))

```

That way it should be possible to pipe the output of the program where you want it.

---

<div class="post-metadata">

**Author:** ![timmm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/timmm/32/6760_2.png) [@timmm](https://discourse.julialang.org/u/timmm)\
**Post date:** [August 13, 2019, 2:28pm UTC](https://discourse.julialang.org/t/running-external-program-getting-the-programs-results-not-just-the-stdout/27499/3 "2019-08-13T14:28:28Z")

</div>

No, I thought this might be too and tried this earlier. This just returns the terminal output in the text file, not the output from the program. I run this as so:

```julia
run(pipeline(`./script`,stdout=pipeline(`sort`,"$OutputFilePathAndName")) );

```

---

<div class="post-metadata">

**Author:** ![Karajan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/karajan/32/8545_2.png) [@Karajan](https://discourse.julialang.org/u/Karajan)\
**Post date:** [August 13, 2019, 2:33pm UTC](https://discourse.julialang.org/t/running-external-program-getting-the-programs-results-not-just-the-stdout/27499/4 "2019-08-13T14:33:03Z")

</div>

I think you don’t need the `sort` or the second `pipeline` here, that is just from the example in the documentation. I also assume that `OutputFilePathAndName` is a string so `"$OutputFilePathAndName" == OutputFilePathAndName`

But I’m a little confused. If you call just the program from the shell, isn’t all output shown there? If so, the `stdout` parameter should catch that. If not, where is it going instead? What is the difference between “terminal output” and “output from the program”?

---

<div class="post-metadata">

**Author:** ![timmm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/timmm/32/6760_2.png) [@timmm](https://discourse.julialang.org/u/timmm)\
**Post date:** [August 13, 2019, 3:28pm UTC](https://discourse.julialang.org/t/running-external-program-getting-the-programs-results-not-just-the-stdout/27499/5 "2019-08-13T15:28:16Z")

</div>

I have spotted a mistake in my code.Your answer made me go back and double check this (and it works).  
Cheers for the advice.  
Tim
