在 Mathematica 中设置环境变量
我需要从 Mathematica 笔记本设置一个环境变量。
Environment["VARIABLE"]
给出变量的值。 但是也可以设置一个变量吗?
I need to set an environment variable from a Mathematica notebook.
Environment["VARIABLE"]
gives the value of the variable. But is it possible to set a variable, too?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
没有内置函数(据我所知),但您可以使用
or
代替。
编辑:您需要查看 Run 和 RunThrough 命令。
There's no built in function (to my knowledge), but you can just use
or
instead.
Edit: You'll want to see the documentation for the Run and RunThrough commands.
使用 Run 或 RunThrough 不会影响 Mathematica 内核本身,但仅对在该内核中启动的进程可见相同的
Run
或RunThrough
命令。如果环境变量应该对 Mathematica 内核进程可见,则基于 gdb 的黑客在 有没有办法改变另一个进程的环境变量?可以在Mac OS X下使用:
Mathematica Put 命令用于启动 gdb 并将其自身附加到 Mathematica 内核进程。 然后,gdb 命令
call (int) putenv ("var=value")
被发送到 stdin 上的 gdb,以使用 putenv。注意:在 Mac OS X 下,只有安装了 Xcode 开发人员工具,gdb 才可用。
Environment variables set up with Run or RunThrough will not affect the Mathematica kernel itself but will only be visible to processes launched within the same
Run
orRunThrough
command.If the environment variable should be visible to the Mathematica kernel process, the gdb based hack described in the accepted answer to Is there a way to change another process's environment variables? can be used under Mac OS X:
The Mathematica Put command is used to launch gdb and have it attach itself to the Mathematica kernel process. The gdb command
call (int) putenv ("var=value")
is then sent to gdb on stdin to set up the environment variable with putenv.Caveat: Under Mac OS X gdb is only available if the Xcode developer tools are installed.
我假设您要在尝试运行外部命令之前执行此操作,对吧?
为什么不直接运行“VARNAME=value; your_original_external_command”
这将临时设置 evn 变量。
I am assuming you are going to do this before you try to run an external command right?
Why not instead just run "VARNAME=value; your_original_external_command"
that will temporarily set the evn variable.