% MINERVA (c) IF Computer 1996,97 % http://www.ifcomputer.com/MINERVA mailto:support@ifcomputer.com :- package('ExecExtension'). :- package('line_io'). % system_lines(+Command,-Lines) <- % NOTE: this works only if the stream is terminated with end_of file character system_lines(Command,Lines) :- system_lines(Command,_ExitValue,Lines). % system_lines(+Command,-ExitValue,-Lines) <- % NOTE: this works only if the stream is terminated with end_of file character % and only if the stream is available fast enough system_lines(Command,ExitValue,Lines) :- process_exec(Command,Process,StreamToCmd,StreamFromCmd,ErrorsFromCmd), close(StreamToCmd), readLines(StreamFromCmd,Lines), waitFor(Process,_WaitValue), exitValue(Process,ExitValue), close(StreamFromCmd), close(ErrorsFromCmd). % system(-Command) <- system(Command) :- system(Command,_ExitValue). % system(+Command,-ExitValue) <- system(Command,ExitValue) :- process_exec(Command,Process,StreamToCmd,StreamFromCmd,ErrorsFromCmd), close(StreamToCmd), waitFor(Process,_WaitValue), exitValue(Process,ExitValue), close(StreamFromCmd), close(ErrorsFromCmd). % process_exec(+Command,-Process,-StreamToCmd,-StreamFromCmd,-ErrorsFromCmd) <- process_exec(Command,Process,StreamToCmd,StreamFromCmd,ErrorsFromCmd) :- process_exec_async(Command,Process,StreamToCmd,StreamFromCmd,ErrorsFromCmd), !. % process_exec_async(+Command,-Process,-StreamToCmd,-StreamFromCmd,-ErrorsFromCmd) <- process_exec_async(Command,Process,StreamToCmd,StreamFromCmd,ErrorsFromCmd) :- getRuntime(Runtime), exec(Runtime, Command, Process), getInputStream(Process, StreamFromCmdPipe), getErrorStream(Process, ErrorsFromCmdPipe), getOutputStream(Process, StreamToCmdPipe), open(StreamFromCmdPipe,read,StreamFromCmd,[stream]), open(ErrorsFromCmdPipe,read,ErrorsFromCmd,[stream]), open(StreamToCmdPipe,write,StreamToCmd,[stream]).