# How to call and get var to/from file.exe

**URL:** <https://discourse.julialang.org/t/how-to-call-and-get-var-to-from-file-exe/24359>\
**Category:** General Usage\
**Created:** [May 18, 2019, 6:28pm UTC](https://discourse.julialang.org/t/how-to-call-and-get-var-to-from-file-exe/24359 "2019-05-18T18:28:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![programista](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/programista/32/5372_2.png) [@programista](https://discourse.julialang.org/u/programista)\
**Post date:** [May 18, 2019, 6:28pm UTC](https://discourse.julialang.org/t/how-to-call-and-get-var-to-from-file-exe/24359/1 "2019-05-18T18:28:07Z")

</div>

in C++  
int main()  
{  
return 70;  
}

compiled program  
zwrot.exe

```julia
julia> cmd = Cmd(`zwrot.exe`)
`zwrot.exe`

julia> run(cmd)
ERROR: failed process: Process(`zwrot.exe`, ProcessExited(70)) [70]
Stacktrace:
 [1] error(::String, ::Base.Process, ::String, ::Int64, ::String) at .\error.jl:42
 [2] pipeline_error at .\process.jl:712 [inlined]
 [3] #run#509(::Bool, ::Function, ::Cmd) at .\process.jl:670
 [4] run(::Cmd) at .\process.jl:668
 [5] top-level scope at none:0

```

How to get the value 70 ?  
Paul

---

<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:** [May 18, 2019, 6:58pm UTC](https://discourse.julialang.org/t/how-to-call-and-get-var-to-from-file-exe/24359/2 "2019-05-18T18:58:29Z")

</div>

```julia
p = run(cmd, wait=false)
wait(p)
p.exitcode

```

---

<div class="post-metadata">

**Author:** ![programista](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/programista/32/5372_2.png) [@programista](https://discourse.julialang.org/u/programista)\
**Post date:** [May 18, 2019, 7:10pm UTC](https://discourse.julialang.org/t/how-to-call-and-get-var-to-from-file-exe/24359/3 "2019-05-18T19:10:16Z")

</div>

Thanks,  
Is posible to call with some argument ( if exe return func ) ?  
Paul

---

<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:** [May 18, 2019, 7:32pm UTC](https://discourse.julialang.org/t/how-to-call-and-get-var-to-from-file-exe/24359/4 "2019-05-18T19:32:25Z")

</div>

> [@programista](#):
>
> Is posible to call with some argument ( if exe return fun ) ?

I don’t understand your question fully, but you can certainly pass arguments to executables via `cmd = `zwrot.exe x` ` or similar.

---

<div class="post-metadata">

**Author:** ![programista](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/programista/32/5372_2.png) [@programista](https://discourse.julialang.org/u/programista)\
**Post date:** [May 19, 2019, 6:42am UTC](https://discourse.julialang.org/t/how-to-call-and-get-var-to-from-file-exe/24359/5 "2019-05-19T06:42:37Z")

</div>

I can t to send argument to file.exe,  
In C++ is :

```julia
#include <iostream>
using namespace std;

int pierwsza(int n);

int main() {
    int n;
    cout<<"Podaj ktora liczbe pierwsza mam wyswielic: ";
    cin>>n;
    cout<<"Jest to liczba: "<<pierwsza(n)<<endl;
    system("pause");
    return 0;
}

int pierwsza(int n) {
    int j=1;
    int wynik=2;
    for (int i=2;j<n;i++) {
        for (int k=2;k<i;k++) {
            if (i%k == 0) {
                break;
            }
            if (k == i-1) {
                j++;
            }
        }
        wynik=i;
    }
    return wynik;
}

```

compiled file C++FirstProject.exe

How to call to exe file with arg ?

```julia
julia> run(Cmd(`C++FirstProject.exe`))
Podaj ktora liczbe pierwsza mam wyswielic:

3
Jest to liczba: 5
Aby kontynuować, naciśnij dowolny klawisz . . .

```

Is OK!  
But if a call run ONLY with arg not works. 😕

```julia
julia> cmd = Cmd(`C++FirstProject.exe`)
`C++FirstProject.exe`

julia> p = run(cmd, 3, wait=false)
ERROR: MethodError: no method matching spawn_opts_swallow(::Int64)
Closest candidates are:
  spawn_opts_swallow() at process.jl:542
  spawn_opts_swallow(::Tuple{Union{RawFD, WindowsRawSocket, FileRedirect, IO},Union{RawFD, WindowsRawSocket, Fil
eRedirect, IO},Union{RawFD, WindowsRawSocket, FileRedirect, IO}}) at process.jl:541
  spawn_opts_swallow(::Union{RawFD, WindowsRawSocket, FileRedirect, IO}) at process.jl:542
  ...
Stacktrace:
 [1] #run#509(::Bool, ::Function, ::Cmd, ::Int64, ::Vararg{Int64,N} where N) at .\process.jl:672
 [2] (::getfield(Base, Symbol("#kw##run")))(::NamedTuple{(:wait,),Tuple{Bool}}, ::typeof(run), ::Cmd, ::Int64, :

```

How to call to exe file with arg =3 and get just 5 ?

Paul
