process_create/3 to run an external bash command and read the output. This is the code:
['-p', Pass, 'ssh', '-l', User, Host, Cmd],
(read_lines(Out, Lines), atomic_list_concat(Lines, " ", Output)),
read_lines/2 is a custom predicate that read all lines of output.)
To go on with my code, I must know if the command succeeded or not. But, reading docs, I didn’t find anything for this purpose.
Is there a way to get the bash exit code of the process?
Thanks in advance.
Is it the small print at the very bottom of the docs?
process_error(Exe, Status) where Status is one of
killed(Signal). Raised if the process is waited for (i.e., Options does not include
process(-PID)), and does not exit with status 0.
So you probably need to catch the error?
ie process_create/3 will throw this particular error if the exit code is not 0. You will also get the exit code as
Using catch/3 is one option. The other is to use the
process(PID) option of process_create/3 and call process_wait/2
Relevant thread: How to get shell echo in Prolog variables
I haven’t gotten around to producing a version using strings, yet.
Thanks for your reply.
process_wait(PID, Exit) and then added a check of
Exit value with
Exit == exit(0).