I have scripts, which do some calculation and I have scripts which setup workers, on a local machine, on remote machines, with a machinefile, etc. I want to pass arguments from the command line, which are in Base.ARGS, to the second script, namely all arguments except e.g. the first - something like
arg1 = ARGS
ARGS = [ARGS[2:end]...]
does not work as we can not reset Base.ARGS. How do I pass arguments to “calculation_script.jl”?
run("julia calculation_script.jl $(join(ARGS, ' '))")
Though honestly, for anything complicated enough to require 2 files, I’d have all the actual calculations in a single script, and have the includes be just functions, types, and constants.
You can. You can for example use
arg1 = popfirst!(ARGS) # ARGS now contains just the rest
or you can use
arg1 = ARGS
tmp = ARGS[2:end]
@fredrikekre Thanks for your answer! This is exactly what I was looking for!
also you have the option to load the setup of workers script with the
julia -L workers.jl script.jl args
@BeastyBlacksmith Thanks for pointing this out as well! Can I pass arguments to
script.jl seperately? E.g. number of workers to
workers.jl and parameters to
From a quick test it seems to me that the arguments you pass are available to both files
julia -L test.jl test.jl a b
So no seperate argument passing, but you can pick out, what you need.
OK. Can I pass arguments as key-value-pairs as well, like --worker_count 4 and --param1 0.43 ? As far as I can see, I can only retrieve the arguments as positions in ARGS, e.g. ARGS, etc ?
Looks promising! I will have a look into it!