【问题标题】:Run prolog from command prompt,get input from file and send output to a file从命令提示符运行 prolog,从文件中获取输入并将输出发送到文件
【发布时间】:2013-04-30 13:30:45
【问题描述】:

我想通过命令提示符运行 swipl prolog,我想将 input.txt 作为查询文件读取并希望将结果输出到 output.txt

我的命令行命令:

swipl -f asd.pl < input.txt > output.txt

但是我的输出结果是在命令提示符下出现并得到空白的 output.txt 文件。

【问题讨论】:

    标签: prolog command-line-tool


    【解决方案1】:

    它适合我。您确定在命令提示符下没有收到错误吗? 注意:要输出 stderr 你应该使用2&gt; filename

    示例(test.pl):

    :- initialization(main).
    
    main:-
      repeat,
        read(Term),
         writeln(term(Term)),
        Term=end_of_file -> halt, fail.
    
    
    swipl.exe -f test.pl < test.pl > test.txt  2> stderr.txt
    

    写在 test.txt:

    term((:-initialization main))
    term((main:-repeat,read(_G747),writeln(term(_G747)),_G747=end_of_file->halt,fail))
    term(end_of_file)
    

    在 stderr.txt 上:

    % c:/swi/workspace/test.pl compiled 0.00 sec, 4 clauses
    

    【讨论】:

    • 我很欣赏你的回答,但我也收到了欢迎消息,例如“欢迎使用它的版本并最终获得 %halt”。如何删除欢迎消息并从 end.i我在 stderr.txt 得到了全部内容,而在 test.txt 没有任何内容。你能告诉我哪个 prolog 版本用于编译。
    • @Himesh:我在 Windows 下使用 SWI 版本 6.2.2。要删除欢迎消息,请使用 -q 修饰符:swipl.exe -q -f test.pl &lt; test.pl &gt; test.txt 2&gt; stderr.txt
    猜你喜欢
    • 1970-01-01
    • 2013-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-16
    • 1970-01-01
    • 2014-09-28
    • 1970-01-01
    相关资源
    最近更新 更多