On Windows, shell/[1,2]
executes the command using the CreateProcess() API and waits for
the command to terminate. If the command ends with a
&
sign, the command is handed to the WinExec()
API, which does not wait for the new task to terminate. See also win_exec/2
and
win_shell/2.
Please note that the CreateProcess() API does not imply
the Windows command interpreter (cmd.exe and therefore commands
that are built in the command interpreter can only be activated using
the command interpreter. For example, a file can be copied using the
command below.
?- shell('cmd.exe /C copy file1.txt file2.txt').
Note that many of the operations that can be achieved using the shell
built-in commands can easily be achieved using Prolog primitives. See
make_directory/1, delete_file/1, rename_file/2,
etc. The clib package provides library(filesex)
,
implementing various high level file operations such as copy_file/2.
Using Prolog primitives instead of shell commands improves the
portability of your program.
The library library(process)
provides process_create/3
and several related primitives that support more fine-grained
interaction with processes, including I/O redirection and management of
asynchronous processes.