Haskell 如何使用readProcessWithExitCode?

Haskell 如何使用readProcessWithExitCode?,haskell,Haskell,此命令在我的终端中运行良好: grep --include=\\*.txt --recursive --regexp='answer' grep --include=\\*.txt --recursive --regexp='answer' 这个在ghci中运行良好: import System.Process r <- readCreateProcessWithExitCode (shell "grep --include=\\*.txt --recursive --regexp='

此命令在我的终端中运行良好:

grep --include=\\*.txt --recursive --regexp='answer'
grep --include=\\*.txt --recursive --regexp='answer'
这个在ghci中运行良好:

import System.Process
r <- readCreateProcessWithExitCode (shell "grep --include=\\*.txt --recursive --regexp='answer'") ""

似乎无法设置以
--

开头的选项您确定此命令在您的终端中有效吗:

grep --include=\\*.txt --recursive --regexp='answer'
grep --include=\\*.txt --recursive --regexp='answer'
在我的系统上,我得到警告:

grep: warning: recursive search of stdin
尝试添加
作为附加参数:

readProcessWithExitCode "grep" ["--include=\\*.txt", "--recursive", "--regexp='answer'", "."] ""
更新

这种将参数传递给
grep
的简单方法对我很有用:

readProcessWithExitCode "grep" ["--include", "*.hs", "--recursive", "--regexp", "answer", "."] ""

您确定此命令在您的终端中有效吗:

grep --include=\\*.txt --recursive --regexp='answer'
grep --include=\\*.txt --recursive --regexp='answer'
在我的系统上,我得到警告:

grep: warning: recursive search of stdin
尝试添加
作为附加参数:

readProcessWithExitCode "grep" ["--include=\\*.txt", "--recursive", "--regexp='answer'", "."] ""
更新

这种将参数传递给
grep
的简单方法对我很有用:

readProcessWithExitCode "grep" ["--include", "*.hs", "--recursive", "--regexp", "answer", "."] ""

我猜,“*.txt”在第一种情况下会被shell扩展?您应该能够使用:
readProcess。。。“grep”[“-r”、“-e”、“answer”]
。另请参阅我的更新答案。我猜,“*.txt”在第一种情况下会被shell扩展?您应该能够使用:
readProcess。。。“grep”[“-r”、“-e”、“answer”]
。还可以看到我的最新答案。是的!它使用
“--include”、“*.txt”
而不是
“--include=\\\*.txt”
。这就是问题所在,
(对我来说)没有问题。事实证明,我有一个较旧版本的
grep
——如果你在没有目录的情况下使用
-r
,新版本会自动假定
。是的!它使用
“--include”、“*.txt”
而不是
“--include=\\\*.txt”
。这就是问题所在,
(对我来说)没有问题。事实证明,我有一个较旧版本的
grep
——如果使用没有目录的
-r
,新版本会自动假定