mathematica 从命令行启动前端和 eval 笔记本
有没有办法从(Windows)命令提示符启动mathematica前端(GUI)并让它评估笔记本而无需进一步的用户操作?
即使 mathematica.exe 采用 -run 和 -initfile 选项,它们的工作方式也不同 就像他们对 math.exe 所做的那样。 (例如,-run ''<
谢谢。第一个答案看起来很有希望,但是我得到了 FrontEndObject::不可用 前端不可用
(顺便说一下,根据文档,它是“UseFrontEnd”。)
也许是路径问题,但是即使在设置 $FrontEndLaunchCommand 之后也没有什么乐趣。
回复:初始化单元 - 这个简单的答案似乎完全符合我的要求需要排除“你想运行初始化吗..”提示框。如果有一个选项可以自动启动内核并运行初始化单元,那么了解这一点将非常有用。
顺便说一句,我正在运行6.0。
Is there a way to start up a mathematica front end (GUI) from a (Windows) command prompt and have it eval a notebook without further user action?
even though mathematica.exe takes the -run and -initfile options they dont work the same
as they do with math.exe. (-run ''<<file.m'' wants to open a file named ''<<file.m'' for example)
Thanks. The first answer looks promising, however I get
FrontEndObject::notavail
A front end is not available
(per docs it is "UseFrontEnd" by the way.)
Perhaps a path issue, however even after setting $FrontEndLaunchCommand no joy..
Re: Initialization Cell -- that simple answer would seem to do exactly what I need excepting for the "do you want to run initialization.." nag box. If there is an option somplace to automatically start a kernel and run initialization cells that would be really useful to know.
I'm running 6.0 by the way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以尝试以下操作:
在 C:\Program Files\Wolfram Research\Mathematica\7.0 中创建一个名为 firstgo.m 的文件,其中包含:
在 C:\Temp 中创建一个名为 Test.nb 的文件,其中包含:
然后在 Windows 命令控制台中运行以下命令:
您将看到 Test.nb 在 Mathematica 目录中创建了一个名为“sin.gif”的文件。 Test.nb 还包含一些打印输出,但尽管在前端运行并在运行后保存,但没有保存打印输出。另外,我还没有找到一种方法来退出内核而不中断前端进程。
附录
如果您知道您的过程将花费多长时间,您可以在完成后使用批处理文件关闭 Mathematica(为下一次运行做好准备)。此示例在关闭 Mathematica 之前暂停 20 秒。请注意,出于演示目的,firstgo.m 现在已移至 C:\Temp。在“我的文档”中创建一个批处理文件 RunFirstGo.bat,其中包含:
然后可以从 Windows 命令控制台运行 RunFirstGo.bat,如下所示:
或者,可以将 RunFirstGo.bat 作为计划任务运行(通过 Windows 控制面板)。
You can try this:
In C:\Program Files\Wolfram Research\Mathematica\7.0 create a file called firstgo.m containing:
And in C:\Temp create a file called Test.nb containing:
Then in a Windows command console run this:
You will see the Test.nb creates a file called 'sin.gif' in the Mathematica directory. Test.nb also contains some Print output, but despite running in the front end and saving after the run there is no print output saved. Also, I have yet to figure out a way to quit the kernel without interrupting the front end process.
Addendum
If you know how long your process is going to take you can use a batch file to close Mathematica when it's done, (ready for the next run). This example pauses 20 seconds before shutting down Mathematica. Note, firstgo.m is now moved to C:\Temp for purpose of demonstration. Create a batch file RunFirstGo.bat in My Documents containing:
RunFirstGo.bat can then be run from a Windows command console like so:
Alternatively, RunFirstGo.bat can be run as Scheduled Task (via Windows Control Panel).
啊哈...!!
跟进..为了完整性 --- 上面的 $FrontEndLaunchCommand 会导致 GUI 出现,以便您可以观察评估(我想要的)。默认情况下是在后台服务器模式下运行前端,因此您可以访问前端功能,但看不到它运行。
Aha...!!
follow up..for completeness --- the above $FrontEndLaunchCommand causes the GUI to come up so you can observe the evaluation (What I wanted). The default is to run a front end in a background server mode, so you have acess to front end functions but cant see it run.
进行评估的不是前端,而是内核。您可以使用 MathematicaScript 来自动化它。
It is not the FrontEnd that does the evaluation but the Kernel. You can use MathematicaScript to automate it.
如果这是针对特定笔记本,您是否尝试将笔记本中的相关单元设置为具有属性 初始化单元格?或者您想使用任何笔记本电脑来执行此操作吗?如果是后者,Sjoerd 的答案效果更好。
If this is for a specific notebook, have you tried setting the relevant cells in the notebook to have the property InitializationCell? Or do you want to do this with any notebook? If the latter, Sjoerd's answer works better.
我不知道该主题是否仍然活跃,但是对于那些因“初始化单元警告”问题而停止的人,您可以将其更改为“Flase”
I don't know if the topic is still active, but for those who are stopped at the "initialization cell warning" problem, you can change this to "Flase" in the