Is it possible to invoke Mathematica's diff functionality from the command line?

烂漫一生 提交于 2019-12-03 14:53:59

Here's a simple example of producing the notebook diff using a Mathematica script.

Save the following as diff.m

Needs["AuthorTools`"]
If[Length[$ScriptCommandLine]>=3, 
    {f1, f2} = $ScriptCommandLine[[{2,3}]], 
    {f1, f2} = {"one.nb", "two.nb"}]
diff = FileNameJoin[{$TemporaryDirectory, "diff.nb"}]
Put[NotebookDiff[f1, f2], diff]
Run["Mathematica " <> diff]
DeleteFile[diff]
Exit[]

Then call it from the command line using MathematicaScript -script diff.m "one.nb" "two.nb". This works on my system (Ubuntu 11.10, Mathematica 8.0.1) and should be platform independent. If you're using a version of Mathematica older than v8, then you'd have to use MathKernel -noprompt -run < diff.m instead of MathematicaScript and the default values for {f1, f2} will be used.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!