Guest User

Untitled

a guest
Apr 11th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.54 KB | None | 0 0
  1. execute(Command, Args, Trace, Trace):-
  2.     process_create(Command, Args, [stdout(pipe(In))]),
  3.     report_command_output(Trace, In),
  4.     close(In).
  5.    
  6. report_command_output(Trace, In):-
  7.     peek_char(In, Char),
  8.     (Char = end_of_file ->
  9.         true
  10.     ;
  11.         read_line(In, Line),
  12.         trace_message(Trace, '~w', [Line]),
  13.         report_command_output(Trace, In)
  14.     ).
  15.    
  16. read_line(In, Line):-
  17.     read_line(In, [], Line).
  18.    
  19. read_line(In, Cs, Line):-
  20.     get_char(In, Char),
  21.     (Char = '\n' ->
  22.         reverse(Cs, Cs1),
  23.         atom_chars(Line, Cs1)
  24.     ;
  25.         read_line(In, [Char|Cs], Line)
  26.     ).
Add Comment
Please, Sign In to add comment