문제

Mathematica 프로그램에 대한 단위 테스트를 시작하고 일부 MakeFiles로 명령 행에서 모든 것을 제어하고 싶습니다.

Mathematica처럼 보입니다 명령 줄에서 실행할 수 있습니다 그러나 Mac OS X 에서이 작업을 시작하는 것에 대한 기본 지침을 볼 수 없습니다. 이전 에이 작업을 수행 한 사람이 있습니까?


업데이트:

이와 같은 테스트 파일 만들기 :

Print["hello"];
x := 1;
y = x+1;
z = y+1;
Print["y="ToString@y];
Print["z="ToString@z];
Quit[];

그리고 그것을 실행합니다

/Applications/Mathematica.app/Contents/MacOS/MathKernel -noprompt < test.m

내가 일종의 배치 처리에 가장 가까운 곳입니다. 하지만 출력은 못 생겼습니다. 스크립트의 모든 라인에 신축성이 추가됩니다!

"hello"




"y=2"

"z=3"

이것이 여전히 콘솔 출력에 정보를 출력 할 수있는 스크립트에 얻을 수있는 가장 가까운 것입니까? 나는 Mathematica 6 만 사용하고 있지만 그것이 차이를 만들지 않기를 바랍니다.

도움이 되었습니까?

해결책

마지막으로, 내가 기대하는 것처럼 출력을 제공합니다.

/Applications/Mathematica.app/Contents/MacOS/MathKernel -noprompt -run "<<test.m"

말이됩니다. 이것을 내에 추가합니다 .bash_profile 쉽게 실행할 수 있습니다 ( mma test.m):

mma () { /Applications/Mathematica.app/Contents/MacOS/MathKernel -noprompt -run "<<$1" ; }

또한보십시오 Dreeves 's mash 이 접근법에 비해 장점을 제공 할 수있는 Perl 스크립트.

다른 팁

약간의 실험으로 나는 그것을 발견했다 /Applications/Mathematica.app/Contents/MacOS/MathKernel 명령 줄에서 시작할 수 있습니다. 평소를 받아들이지 않는 것 같습니다 -h 또는 --help 그러나 명령 줄 깃발.

Mash Plug의 Pillsy와 Will Robertson에게 감사합니다! 관련 stackoverflow 질문은 다음과 같습니다. 명령 줄에서 명령 줄 Args, stdin, stdout 및 stderr와 함께 Mathematica 프로그램을 호출하십시오.

Mash를 사용하지 않으면 Mash가 정의하는 다음 유틸리티 기능을 사용하려고 할 수 있습니다. 예를 들어, 표준 프린트는 일반적으로 스크립트에서 원하는 것이 아니라 인용 표시가있는 문자열을 인쇄합니다.

ARGV = args = Drop[$CommandLine, 4];         (* Command line args.            *)
pr = WriteString["stdout", ##]&;             (* More                          *)
prn = pr[##, "\n"]&;                         (*  convenient                   *)
perr = WriteString["stderr", ##]&;           (*   print                       *)
perrn = perr[##, "\n"]&;                     (*    statements.                *)
EOF = EndOfFile;                             (* I wish mathematica            *)
eval = ToExpression;                         (*  weren't so damn              *)
re = RegularExpression;                      (*   verbose!                    *)
read[] := InputString[""];                   (* Grab a line from stdin.       *)
doList[f_, test_] :=                         (* Accumulate list of what f[]   *)
  Most@NestWhileList[f[]&, f[], test];       (*  returns while test is true.  *)
readList[] := doList[read, #=!=EOF&];        (* Slurp list'o'lines from stdin *)

Mash를 사용하려면 해당 Perl 파일을 잡고 mash.pl, 다음과 같이 테스트를 수행하십시오.

#!/usr/bin/env /path/to/mash.pl

prn["hello"];
x := 1;
y = x+1;
z = y+1;
prn["y=", y];
prn["z=", z];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top