Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

As a test I want a simple script to take a command line argument and print it to a file:

Export["c://cygwin/home/jorgen/yu.dat",$ScriptCommandLine[[2]],"Data"] // MatrixForm;

However when I run this with ./MathKernel -script Swargtest.m 45 the resulting file yu.dat looks like this:


I've tried what I could think of: making another variable with out=$ScriptCommandLine[[2]] and exporting that, removing the $, running the script with '45' and "45" on the command line, etc.

I'm using cygwin on a windows 7 machine.

share|improve this question
I see no extra argument (such as your 45) allowed AFTER the file name mentioned here: , Where did you see such a possible argument at that position? It says: -script "file" execute the commands from the in a script mode – Nasser Sep 2 '13 at 12:59
From the docs: "If the Mathematica kernel was run in a way other than via a MathematicaScript mechanism, the $ScriptCommandLine gives an empty list." – Pickett Sep 2 '13 at 13:05
Oh I see now, I have to use $CommandLine. My bad! What's the custom here, should I delete this question? – jorgen Sep 2 '13 at 13:09
@jorgen: I think it would be best if you provide an answer and accept it. It is common and welcomed to answer one's own questions and also to accept it. You might want to refer to Anons comment in this case... – Albert Retey Sep 3 '13 at 9:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.