Calling a julia script from within another script

Here is how you can do it if you (for any reason) prefer this approach.

Let’s put this in the script to be called from another script (let’s say A.jl):

x = ARGS[1]
callx(x) = parse(Int, x) + 1
println(callx(x))

Now, in the script that will call/execute A.jl, we can add (let’s call this B.jl):

myx = 5
output = readchomp(`julia A.jl $myx`)
println("I received: $output from script execution of A.jl...")

Now, if I go in terminal and run:

julia B.jl

… you’ll see the script B.jl calling A.jl and you’ll get the following output:

I received: 6 from script execution of A.jl...

In this way, you don’t need to care about what the functions are called inside A.jl - you just need to make sure you are printing stuff to stdout.

Have fun.

1 Like