How to get output value from python script executed in swi-prolog

How can I create a program swi-prologthat executes a Python file score.pyand gets the result?

I read about process_create/3and exec/1, but I can not find a lot of documentation

+4
source share
1 answer

You need to use the options stdout/1andstderr/1 process_create/3.

For example, here is a simple predicate that simply copies the output of a process to standard output:

output_from_process (Exec, Args): -
        process_create (Exec, Args, [stdout (pipe (Stream)),
                                    stderr (pipe (Stream))]),
        copy_stream_data (Stream, current_output),
        % the process may terminate with any exit code.
        catch(close(Stream), error(process_error(_,exit(_)), _), true).

copy_stream_data/2 .

+2

Source: https://habr.com/ru/post/1683101/


All Articles