How to run external commands?

Can anyone guide me run an external command and get its return output? I failed with process_create:

?- process_create(path(ls), ['-l'], []).

Have you looked at the test cases for process_create/3 in

Which OS are you using?

What do you get from this query:
absolute_file_name(path(ls), Abs).

I am using Debian 10.6, swi-prolog 8.0.2.

?- absolute_file_name(path(ls), Abs).
Abs = ‘/usr/bin/ls’.

Hmmm … it works for me on Ubuntu, SWI-Prolog 8.3.10. And presumably you get the same result with process_create('/bin/ls', [], [])? (or '/usr/bin/ls').

process_create/3 is documented as det, so it shouldn’t fail.
I wonder if this works for you: process_create(path(echo), [hello], []).
How about shell(ls)?

I’ve just restarted the Prolog shell, and it gives me some different results:

?- process_create(path(ls), ['-l'], []).
total 4
-rw-r--r-- 1 notooth notooth 106 Oct 28 08:30

?- process_create(path(ls), [], [stdout(pipe(Var))]).
Var = <stream>(0x55b96a953a40).

This looks normal. Wondering what could have caused a failure before the restart. I guess we’ll never know :frowning:

I put the code in file and run $ swipl Then the shell caused that failure.

Tried this (file

:- initialization process_create(path(ls), ['-l'], []).

Then in the shell

total 10084
drwxr-xr-x  2 janw janw    4096 Feb 12  2020 a
-rwxr-xr-x  1 janw janw    8361 Apr 29 11:05
-rw-r--r--  1 janw janw    1528 Jun  5  2019 ac2_tests.P
-rw-r--r--  1 janw janw       7 Aug  6 10:33 хелло.pl
Welcome to SWI-Prolog (threaded, 64 bits, version 8.3.10-11-g6801fa53e-DIRTY)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

    CMake built from "/home/janw/src/swipl-devel/linux"

For online help and background, visit
For built-in help, use ?- help(Topic). or ?- apropos(Word).

101 ?- ^D

Looks good to me. Please be very precise in your instructions. Quite likely you found some problem. The (in my view) most obvious way to reproduce it doesn’t work though.

Note that @notooth is also using 8.0.2

Could indeed be an old bug. I don’t have 8.0.2 around. I’d need to rebuild it :slight_smile:

2 posts were split to a new topic: Is there a tutorial about programming in .pl files?