Here is my shell script so far (I am using MacOSX):

$math -run "<<input" -script script1.wl script2.wl > output

The two scripts I want to run in a row are script1.wl and script2.wl. The above seems to only run script1.wl

Anything obvious I am missing ?

  • $\begingroup$ I've never used the -script option. What happens if you simply use $math -run "<<input;<<script1.wl;<< script2.wl" > output? $\endgroup$
    – Jason B.
    Mar 15 '17 at 16:32
  • $\begingroup$ If you want to run them with the same kernel, why don't you run them from within Mathematica (Get) instead of from within a shell script? $\endgroup$
    – Szabolcs
    Mar 15 '17 at 16:43
  • $\begingroup$ @Szabolcs - sometimes you just don't want to be burdened with a front end :-) $\endgroup$
    – Jason B.
    Mar 15 '17 at 16:54
  • $\begingroup$ @JasonB. I am not talking about the front end. I just don't think that it is a good idea to mix Mathematica will shell scripts. I meant: write Mathematica code to read in the two "scripts", not shell code. $\endgroup$
    – Szabolcs
    Mar 15 '17 at 16:56
  • 1
    $\begingroup$ @JasonB. That's essentially the same what you said. Sorry. I didn't red carefully. $\endgroup$
    – Szabolcs
    Mar 15 '17 at 16:58

I can't see any syntax on this page for using 2 files with the -script option (and as MB1965 points out, the help does say that only one script file can be used with the -script option). I do have some experience running WL files from the command line in Mathematica in batch mode, all of which I learned from Jens's page here.

If I create a file called "script1.wl" with the contents

x1 = 3;
x2 = 4;

and another file in the same directory, "script2.wl", with

Print[x1 + x2];

and then run this command from the same directory

math -noprompt -run "<<script1.wl;<<script2.wl" > output

where I've set math up as an alias in my shell to the MathKernel application, then the output file has a single line

  • 2
    $\begingroup$ Similarly if you run RunProcess[{$script, "-help"}, "StandardOutput"] it specifies that only one file can be passed. $\endgroup$
    – b3m2a1
    Mar 15 '17 at 17:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.