Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell 使用Haskell运行可执行文件 P>说,我用一个C++代码编译成一个可执行文件: g++ test.cpp -o testcpp 我可以使用终端(我使用OS X)来运行,并提供一个输入文件来处理C++程序,如: ./testcpp < input.txt_Shell_Haskell_Command Line Arguments_Executable - Fatal编程技术网

Shell 使用Haskell运行可执行文件 P>说,我用一个C++代码编译成一个可执行文件: g++ test.cpp -o testcpp 我可以使用终端(我使用OS X)来运行,并提供一个输入文件来处理C++程序,如: ./testcpp < input.txt

Shell 使用Haskell运行可执行文件 P>说,我用一个C++代码编译成一个可执行文件: g++ test.cpp -o testcpp 我可以使用终端(我使用OS X)来运行,并提供一个输入文件来处理C++程序,如: ./testcpp < input.txt,shell,haskell,command-line-arguments,executable,Shell,Haskell,Command Line Arguments,Executable,或: 所以我的问题是,哈斯克尔是否有可能做到这一点。如果是,我应该如何使用以及使用哪些模块/功能?谢谢 编辑 好的,正如David所建议的,我删除了输入参数并尝试运行它。这样做有效: out <- readProcess "./testcpp" [] "" out 当它要求标准输入时不是要求读取输入的文件,而是要求读取文件标准输入的实际内容 因此,您需要使用或类似工具来获取测试的内容。在中: input <- readFile "test.in" out <- readPro

或:

所以我的问题是,哈斯克尔是否有可能做到这一点。如果是,我应该如何使用以及使用哪些模块/功能?谢谢

编辑

好的,正如David所建议的,我删除了输入参数并尝试运行它。这样做有效:

out <- readProcess "./testcpp" [] ""
out

当它要求
标准输入时
不是要求读取输入的文件,而是要求读取文件标准输入的实际内容

因此,您需要使用或类似工具来获取
测试的内容。在
中:

input <- readFile "test.in"
out <- readProcess "./testcpp" [] input
输入显示:

当它要求
标准输入时
不是要求读取输入的文件,而是要求读取文件标准输入的实际内容

因此,您需要使用或类似工具来获取
测试的内容。在
中:

input <- readFile "test.in"
out <- readProcess "./testcpp" [] input

input在第一部分中,您有一个名为
test
的可执行文件,在第二部分中,您试图运行一个名为
testcpp
的可执行文件。这是正确的吗?另外,我认为您需要阅读
test.in
中的内容,然后将该字符串作为最后一个参数传递,而不是给出文件名。@davidyong是的,我只是提供了我尝试执行的一般示例。但由于它看起来令人困惑,我编辑了它。至于你评论的第二部分,我不太明白你的意思。好的,问题在于运行exec文件本身,而不是提供输入参数。您始终可以使用shell脚本创建一个文件并运行它。在第一部分中,您有一个名为
test
的可执行文件,在第二部分中,您尝试运行一个名为
testcpp
的可执行文件。这是正确的吗?另外,我认为您需要阅读
test.in
中的内容,然后将该字符串作为最后一个参数传递,而不是给出文件名。@davidyong是的,我只是提供了我尝试执行的一般示例。但由于它看起来令人困惑,我编辑了它。至于你评论的第二部分,我不太明白你的意思。好的,问题在于运行exec文件本身,而不是提供输入参数。您可以始终使用shell脚本创建一个文件,然后运行它。是的!成功了。谢谢你的回答和清楚的解释:)是的!成功了。谢谢你的回答和清楚的解释:)
testcpp: readProcess: runInteractiveProcess: exec: does not exist (No such file or directory)
out <- readProcess "./testcpp" [] ""
readProcess
  :: FilePath   Filename of the executable (see RawCommand for details)
  -> [String]   any arguments
  -> String     standard input
  -> IO String  stdout
input <- readFile "test.in"
out <- readProcess "./testcpp" [] input