How to get shell echo in Prolog variables

I see.
However still it is not clear for me how to separate a string into such atoms as this case.
Anyway on this question, I have to take time to learn how the first argument (input command as a list) is processed by process_create and thread_create.
Thanks.

EDIT

I tried to follow a sample codes in help(process_create) like below, which
was surprisingly simple, though I am far from familiar with process things.
Anyway the sample codes seems enough for my purpose to call simple shell command from Prolog codes.

Thanks @brebs and @Jan

% ?- choose_folder(X).
%@ 2023-05-17 00:11:05.073 osascript[48546:12223914] +[CATransaction synchronize] called within transaction
%@ X = ['/Users/cantor/Desktop/pdfs/'].

choose_folder(Lines) :-
                setup_call_cleanup(
                    process_create(path(choosefolder), [],
                                   [ stdout(pipe(Out))
                                   ]),
                    read_lines(Out, Lines),
                    close(Out)).
read_lines(Out, Lines) :-
                read_line_to_codes(Out, Line1),
                read_lines(Line1, Out, Lines).

read_lines(end_of_file, _, []) :- !.
read_lines(Codes, Out, [Line|Lines]) :-
                atom_codes(Line, Codes),
                read_line_to_codes(Out, Line2),
                read_lines(Line2, Out, Lines).

That is all you need for the simple case yes. You can read a bit faster using something like this. read_string/5 is established common ground with ECLiPSe.

read_lines_as_atoms(Stream, Lines) :-
    read_string(Stream, "\n", "", Sep, String),
    (   Sep == -1
    ->  Lines = []
    ;   atom_string(Line, String),
        Lines = [Line|Rest],
        read_lines_as_atoms(Stream, Rest)
    ).

I suggest “obsolete” instead of “deprecated” for this situation - and add a pointer in the documentation to the functionality that replaces the obsolete code.

4 Likes

Thanks. That makes sense. In general deprecated also points/should point at the replacement.

Ideally we’d add @obsolete to PlDoc and the rest of the documentation infra and replace many deprecated.

3 Likes