问题
Whenever I compile anything with swi-prolog, it adds |:
before user input to show that you are supposed to write something, which would be fine, but I need to pipe the output of this program to another program, preferably without the |:
.
My compilation options are:
swipl -nodebug -g true -O -q --toplevel=quiet --stand_alone=true -o main -c main.pl
回答1:
You need to say
prompt(_, '')
somewhere in your program before you start reading and writing to standard streams. From the entry for prompt/2:
A prompt is printed if one of the read predicates is called and the cursor is at the left margin. It is also printed whenever a newline is given and the term has not been terminated. Prompts are only printed when the current input stream is user.
The invocation above just sets the prompt to the empty atom (ignoring whatever the prompt was before). For example, with the following prompt.pl
:
:- current_prolog_flag(verbose, silent).
:- use_module(library(readutil)).
main :-
read_line_to_codes(user_input, Line),
format("~s~n", [Line]),
halt.
main :- halt(1).
Then:
$ swipl -q --goal=main -o prompt -c prompt.pl
$ ./prompt
|:foobar
foobar
$
:- current_prolog_flag(verbose, silent). :- use_module(library(readutil)). main :- prompt(_, ''), read_line_to_codes(user_input, Line), format("~s~n", [Line]), halt. main :- halt(1).
And it is gone:
$ swipl -q --goal=main -o prompt -c prompt.pl
$ ./prompt
foobar
foobar
$
If you have included a program similar to my first version of prompt.pl
and the resulting output it might have been easier for more people to understand what exactly you are asking.
来源:https://stackoverflow.com/questions/30561323/swi-prolog-remove-before-user-input-in-compiled-program