从 MATLAB 中查找已安装程序的路径?
我可以从MATLAB命令行中找到特定程序的安装路径吗? 或者我可以找到已注册程序的路径(相当于 Windows reg)吗?
Can I find out from the MATLAB command line what is the installation path of specific program?
Or can I find the path for a registered program (Windows reg equivalent)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这不会是 100% 可靠,但大多数情况下都会得到正确的答案:
示例用法:
根据您的操作系统,您可能可以直接从系统获取此信息:
which
可在安装了 Cygwin 的 Unix 系统和 Windows 系统上使用:where
可在<一href="https://superuser.com/questions/276736/which-versions-configurations-of-microsoft-windows-include-the-where-command">Windows 2003 及更高版本:在某些情况下,您可以使用 winqueryreg,例如:
This won't be 100% reliable, but this will get the right answer most of the time:
Sample usage:
Depending on your OS, you might be able to get this information from the system directly:
which
is available on Unix systems and Windows systems with Cygwin installed:where
is available on Windows 2003 and later:And in some cases, you can pull this information from the registry using winqueryreg, for example:
调用
DOS/bash 命令which
,例如(或使用
system
而不是!
。)编辑: Windows 中似乎没有直接的等效项。我在(Win XP)机器上安装了 cygwin,并进行了尝试,命令成功。或者,请查看 stackoverflow 和 < a href="https://superuser.com/questions/49104/handy-tool-to-find-executable-program-location">超级用户。
Call the
DOS/bash commandwhich
, e.g.,(Or use
system
instead of the!
.)EDIT: It seems that there isn't a direct equivalent in Windows. I had cygwin installed on the (Win XP) machine I tried it on, and the command succeeded. Alternatively, take a look at these answers on stackoverflow and superuser.
这取决于您对操作系统的了解以及您的程序具有哪些属性。
在 Linux 上我通常会做这样的事情:
它看起来不漂亮,而且远非便携(我想它不能在 Windows 上工作,也许只有当你安装 Cygwin 或类似的东西时)。在 Unix 中要容易得多,因为大多数可执行文件都可以从“路径”(环境变量“路径”)访问,而在 Windows 中,大多数可执行文件要么存储在 Windows 目录中(位于默认路径中,因此可以找到它们),要么在 Program Files 目录中,据我所知,该目录并不存在。
当找到程序时,错误 = 0,并且
path
显然包含可执行文件的路径。对于 Windows,我想您可以搜索该程序的所有目录,但这可能有点乏味。
This depends on what you know about the OS and what properties your program has.
On Linux I usually do something like:
It doesn't look pretty and it's far from portable (I suppose it will not work on Windows, perhaps only if you install Cygwin or something similar). It's far easier in Unix since most executables are accessible from the "path" (the environment variable "path"), while in Windows most executables are either stored in the Windows directory (which is in the default path, so they are found) or in a Program Files directory which is not as far as I recall.
Error = 0 when the program is found and
path
then obviously contains the path to the executable.For Windows I guess you can search all directories for the program, but that might be somewhat tedious.
MATLAB 并不是真正设计用来作为搜索驱动器上任何位置的文件的工具。这是一项最好留给操作系统的任务,Egon 建议的就是你应该做的。只需将
which
替换为 DOS 中的等效项(您应该已经知道这一点,否则只需在 MS-DOS/Windows 标记中询问另一个问题。它可能已经得到解答。)。如果您真的一心想要使用 MATLAB 来搜索驱动器,那么您可以执行以下操作
,请注意,第一步将需要一段时间。
MATLAB is not really designed to be used as a tool to search files anywhere on the drive. That's a task best left to the OS, and what Egon suggested is what you should be doing. Simply replace
which
with the equivalent in DOS (you should know this already, else just ask another question in the MS-DOS/Windows tag. It probably has already been answered.).If you are really hell bent on using MATLAB to search the drive, then you can do the following
Beware, the first step will take a while.