相关疑难解决方法(0)

从命令行调用Mathematica程序,使用命令行args,stdin,stdout和stderr

如果在foo.m中有Mathematica代码,Mathematica可以用-noprompt-initfile foo.m (或-run "<<foo.m")调用,并且命令行参数可用$CommandLine(在那里有额外的垃圾)但是有没有办法让一些mathematica代码像

#!/usr/bin/env MathKernel
x = 2+2;
Print[x];
Print["There were ", Length[ARGV], " args passed in on the command line."];
linesFromStdin = readList[];
etc.
Run Code Online (Sandbox Code Playgroud)

和chmod它可执行并运行它?换句话说,如何像任何其他脚本语言(Perl,Python,Ruby等)一样使用Mathematica?

scripting command-line wolfram-mathematica

17
推荐指数
3
解决办法
1万
查看次数