2
$\begingroup$

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:

{}[[2]]

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.

$\endgroup$
4
  • 1
    $\begingroup$ I see no extra argument (such as your 45) allowed AFTER the file name mentioned here: reference.wolfram.com/mathematica/ref/program/MathKernel.html , Where did you see such a possible argument at that position? It says: -script "file" execute the commands from the in a script mode $\endgroup$
    – Nasser
    Sep 2, 2013 at 12:59
  • $\begingroup$ From the docs: "If the Mathematica kernel was run in a way other than via a MathematicaScript mechanism, the $ScriptCommandLine gives an empty list." $\endgroup$
    – C. E.
    Sep 2, 2013 at 13:05
  • 1
    $\begingroup$ Oh I see now, I have to use $CommandLine. My bad! What's the custom here, should I delete this question? $\endgroup$
    – jorgen
    Sep 2, 2013 at 13:09
  • 1
    $\begingroup$ @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... $\endgroup$ Sep 3, 2013 at 9:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.