gpt4 book ai didi

command-line - 调用命令行程序

转载 作者:行者123 更新时间:2023-12-03 07:47:17 24 4
gpt4 key购买 nike

我有一个可执行文件,双击后会在命令行窗口中打开。 enter image description here

现在,可执行文件 apame_win64.exe 所在的目录中有一个输入文件(即名为“sphere_15000.inp”)。所以我们可以在命令行中插入文件名。 enter image description here

问题是如何从mathematica 前端完成此操作?使用 RunThrough 命令,我尝试执行此操作,但没有成功。

RunThrough["Executable Location", "sphere_15000"]

我需要将此文件位置放入 Windows 7 环境路径变量中吗?希望大家在这方面给点建议。

更新

找到了解决我的问题的方法。

  1. 首先将 Mathematica 目录设置为可执行文件所在的文件夹。

    path="C:\Users\FlowCrusher\Desktop\CUSP 求解器\Apame_build_2011_01_09\solver";设置目录[路径];

  2. 然后使用以下输入样式。

    运行["\"\"apame_win64.exe\"\"输入\"\""]

这里“apame_win64.exe”是要运行的可执行文件,“input”是可执行文件的输入文件。这解决了问题。但愿望 list 中有一个新项目。

有办法在后台隐藏控制台窗口吗?

这是它在我的屏幕上的样子。 enter image description here

正如 Chris 所建议的,如果我们在运行命令中使用最小化控制台,我们会得到一个最小化窗口,但程序不会执行。

enter image description here

我希望有一个解决方案。

BR

最佳答案

是的,您可以将可执行文件的文件夹放入 Path 变量中,或提供完整路径名。

但是,RunThrough 似乎已被(在 Windows 上)取代Import["!command ","Text"],它将执行命令并将 comaand 行输出作为字符串读取到 Matheamtica 中。例如:

Export["testit.txt", "bla", "Text"];
Import["!dir" <> " testit* > dir.log", "Text"];
FilePrint["dir.log"]

--

否则,我过去使用 NETLink 也取得了很好的结果(不确定 WScript.shell 是否仍然适用于 Windows7/8 或者如果应该使用其他东西)。模拟运行(我认为 RunThrough 并不是真正需要的):

Run2[cmd_String] := Module[{shell},
Switch[$OperatingSystem,
"Windows",
Needs["NETLink`"];
shell = NETLink`CreateCOMObject["WScript.shell"];
shell @ run[cmd,0,True],
"Unix",
Run @ cmd,
"MacOSX",
Run @ cmd ] ];

关于command-line - 调用命令行程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7644881/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com