ページ

2014年5月27日火曜日

MathemathicaScript の引数

MathematicaScriptの引数の引き渡しをいつも忘れてしまうので覚え書き.

MathematicaScriptの引数は

 $ScriptCommandLine
渡され,一番目はScriptのファイル名,2番目から引数となる.引数の制御は

If [Length[$ScriptCommandLine] !=2, 
 Print["usage: MathematicaScript -script" <> $ScriptCommandLine[[1]] <> " value1"];
 Exit[1] ]

とでもしておけば良い.引数はstringで受け取るので,実数とかにしたければ
ToExpression@$ScriptCommandLine[[2]]

とでもすればよい.