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

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

compiled program
zwrot.exe

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

p = run(cmd, wait=false)
wait(p)
p.exitcode
2 Likes

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

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

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

#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> 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. :confused:

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