1:- module(system_ssardina, 2 [ 3 run_python/3 4 ]). 5 6:- use_module(library(http/http_open)). 7:- use_module(library(socket)). 8:- use_module(library(debug)).
e.g., run_python('script.py', ['arg1', 'arg2'], Status).
19run_python(Script, Args, Status) :-
20 (exists_file(Script)
21 -> true
22 ;
23 throw(error(existence_error(file, Script), _))
24 ),
25 process_create(path(python),
26 [Script|Args],
27 [stdout(pipe(Out)), stderr(pipe(Err)), process(PID)]),
28 read_string(Out, _, StdOut),
29 read_string(Err, _, StdErr),
30 % always read before finishing process (output too large for OS buffers)
31 close(Out),
32 close(Err),
33 process_wait(PID, Status),
34 debug(debug, "Python ID and status: ~d - ~w~n", [PID, Status]),
35 debug(debug, "Python output: ~s~n", [StdOut]),
36 debug(debug, "Python error: ~s~n", [StdErr])