code_junkie

Call a Mathematica program from the command line, with command-line args, stdin, stdout, and stderr

Nov 11th, 2011
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. #!/usr/bin/env MathKernel
  2. x = 2+2;
  3. Print[x];
  4. Print["There were ", Length[ARGV], " args passed in on the command line."];
  5. linesFromStdin = readList[];
  6. etc.
  7.  
  8. #!/bin/sh
  9. exec <"$0" || exit; read; read; exec /usr/local/bin/math -noprompt "$@" | sed '/^$/d'; exit
  10. (* Mathematica code starts here *)
  11. x = 2+2;
  12. Print[x];
  13.  
  14. export PATH=$PATH:/Applications/Mathematica.app/Contents/MacOS
  15.  
  16. #!/usr/bin/env MathKernel -script
  17.  
  18. $ cat hello.ma
  19. #!/usr/bin/env MathKernel -script
  20.  
  21. Print["Hello World!"]
  22.  
  23. $ chmod a+x hello.ma
  24. $ ./hello.ma
  25. "Hello World!"
Add Comment
Please, Sign In to add comment