如何判断在Haskell中的Linux上是否安装了程序
我正在创建一个使用与服务器交互的外部程序的脚本。 我想首先测试该程序在尝试使用之前已安装。
我查找了判断是否安装程序并找到此帖子的首选方法: 如何检查程序是否存在从bash脚本?
tldr:它推荐“命令-v< prog -name>”在“< prog-name>”上因为它是POSIX兼容的。命令应返回0,如果找到程序,> 0否则。
因此,我从system.process中使用readProcessWithExitCode
如下所示,
readProcessWithExitCode "command" ["-v", "<some-program>"] ""
我在GHCI中进行测试时会收到以下错误
:readCreatCreateProcessWithExitCode:posix_spawnp:posix_spawnp:不存在(没有这样的文件或目录),
我尝试使用哪个' “命令”。它告诉我它不存在,尽管我可以使用它,并且它可以按照我终端中的人页页面所述工作。
这里发生了什么,我如何看到使用Haskell安装的东西?
一些系统信息:
- GHC:9.0.2
- 解析器:LTS-1911
- “我使用Arch btw”
I'm creating a script that uses an external program that interacts with a server.
I want to test first that the program is installed before trying to use it.
I looked up the preferred way to tell if a program was installed and found this post:
How can I check if a program exists from a Bash script?
TLDR: It recommends "command -v <prog-name>" over "which <prog-name>" since it is POSIX compatible. The command should return 0 if the program was found, >0 otherwise.
So I used readProcessWithExitCode
from System.Process as follows
readProcessWithExitCode "command" ["-v", "<some-program>"] ""
I get the following error when testing in GHCI
Exception: command: readCreateProcessWithExitCode: posix_spawnp: does not exist (No such file or directory)
I tried to use 'which' on 'command'. It tells me it does not exist although I can use it and it works as described in the man pages in my terminal.
What's going on here and how do I see if something is installed using Haskell?
Some system information:
- GHC: 9.0.2
- resolver: lts-19.11
- "I use Arch btw"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议您只需运行要运行的程序,并在不可用的情况下捕获例外。像这样:
I recommend that you simply run the program you want to run, and catch the exception you get if it isn't available. Like this: