Creates a new process to run the specified shell command. If the
command returns a non-zero exit code, an exception is raised.
If an asynchronous exception is thrown to the thread executing
callCommand, the forked process will be terminated and
callCommand will wait (block) until the process has been
terminated.
Creates a new process to run the specified command with the given
arguments, and wait for it to finish. If the command returns a non-zero
exit code, an exception is raised.
If an asynchronous exception is thrown to the thread executing
callProcess, the forked process will be terminated and
callProcess will wait (block) until the process has been
terminated.
This is the most general way to spawn an external process. The
process can be a command line to be executed by a shell or a raw command
with a list of arguments. The stdin, stdout, and stderr streams of
the new process may individually be attached to new pipes, to existing
Handles, or just inherited from the parent (the default.)
The details of how to create the process are passed in the
CreateProcess record. To make it easier to construct a
CreateProcess, the functions proc and shell are supplied that
fill in the fields with default values which can be overriden as
needed.
createProcess returns (mb_stdin_hdl, mb_stdout_hdl, mb_stderr_hdl, ph),
where
if std_in == CreatePipe, then mb_stdin_hdl will be Just h,
where h is the write end of the pipe connected to the child
process's stdin.
otherwise, mb_stdin_hdl == Nothing
Similarly for mb_stdout_hdl and mb_stderr_hdl.
For example, to execute a simple ls command:
r <- createProcess (proc "ls" [])
To create a pipe from which to read the output of ls:
(_, Just hout, _, _) <-
createProcess (proc "ls" []){ cwd = Just "/home/bob",
std_out = CreatePipe }
Note that Handles provided for std_in, std_out, or std_err via the
UseHandle constructor will be closed by calling this function. This is not
always the desired behavior. In cases where you would like to leave the
Handle open after spawning the child process, please use createProcess_
instead. All created Handles are initially in text mode; if you need them
to be in binary mode then use hSetBinaryMode.
ph contains a handle to the running process. On Windows
use_process_jobs can be set in CreateProcess in order to create a
Win32 Job object to monitor a process tree's progress. If it is set
then that job is also returned inside ph. ph can be used to
kill all running sub-processes. This feature has been available since
1.5.0.0.
Returns the PID (process ID) of the current process. On POSIX systems,
this calls getProcessID from System.Posix.Process in the unix package.
On Windows, this calls getCurrentProcessId from System.Win32.Process in
the Win32 package.
Nothing is returned if the handle was already closed. Otherwise a
PID is returned that remains valid as long as the handle is open.
The operating system may reuse the PID as soon as the last handle to
the process is closed.
This is a non-blocking version of waitForProcess. If the process is
still running, Nothing is returned. If the process has exited, then
Just e is returned where e is the exit code of the process.
On Unix systems, see waitForProcess for the meaning of exit codes
when the process died as the result of a signal. May throw
UserInterrupt when using delegate_ctlc.
The computation rawSystemcmdargs runs the operating system command
cmd in such a way that it receives as arguments the args strings
exactly as given, with no funny escaping or shell meta-syntax expansion.
It will therefore behave more portably between operating systems than system.
The return codes and possible failures are the same as for system.
readProcess forks an external process, reads its standard output
strictly, blocking until the process terminates, and returns the output
string. The external process inherits the standard error.
If an asynchronous exception is thrown to the thread executing
readProcess, the forked process will be terminated and readProcess will
wait (block) until the process has been terminated.
Output is returned strictly, so this is not suitable for launching processes
that require interaction over the standard file streams.
Runs a raw command, optionally specifying Handles from which to
take the stdin, stdout and stderr channels for the new
process (otherwise these handles are inherited from the current
process).
Any Handles passed to runProcess are placed immediately in the
closed state.
Given a program p and arguments args,
showCommandForUser pargs returns a string suitable for pasting
into /bin/sh (on Unix systems) or CMD.EXE (on Windows).
Creates a new process to run the specified raw command with the given
arguments. It does not wait for the program to finish, but returns the
ProcessHandle.
Attempts to terminate the specified process. This function should
not be used under normal circumstances - no guarantees are given regarding
how cleanly the process is terminated. To check whether the process
has indeed terminated, use getProcessExitCode.
On Unix systems, terminateProcess sends the process the SIGTERM signal.
On Windows systems, if use_process_jobs is True then the Win32 TerminateJobObject
function is called to kill all processes associated with the job and passing the
exit code of 1 to each of them. Otherwise if use_process_jobs is False then the
Win32 TerminateProcess function is called, passing an exit code of 1.
Note: on Windows, if the process was a shell command created by
createProcess with shell, or created by runCommand or
runInteractiveCommand, then terminateProcess will only
terminate the shell, not the command itself. On Unix systems, both
processes are in a process group and will be terminated together.
Waits for the specified process to terminate, and returns its exit code.
On Unix systems, may throw UserInterrupt when using delegate_ctlc.
GHC Note: in order to call waitForProcess without blocking all the
other threads in the system, you must compile the program with
-threaded.
Note that it is safe to call waitForProcess for the same process in multiple
threads. When the process ends, threads blocking on this call will wake in
FIFO order. When using delegate_ctlc and the process is interrupted, only
the first waiting thread will throw UserInterrupt.
(Since: 1.2.0.0) On Unix systems, a negative value ExitFailure -signum
indicates that the child was terminated by signal signum.
The signal numbers are platform-specific, so to test for a specific signal use
the constants provided by System.Posix.Signals in the unix package.
Note: core dumps are not reported, use System.Posix.Process if you need this
detail.
Does automatic cleanup when the action finishes. If there is an exception
in the body then it ensures that the process gets terminated and any
CreatePipeHandles are closed. In particular this means that if the
Haskell thread is killed (e.g. killThread), that the external process is
also terminated.
Create a pipe for interprocess communication and return a
(readEnd, writeEnd)Handle pair.
WinIO Support
When this function is used with WinIO enabled it's the caller's
responsibility to register the handles with the I/O manager.
If this is not done the operation will deadlock. Association can
be done as follows:
Only associate handles that you are in charge of read/writing to.
Do not associate handles passed to another process. It's the
process's responsibility to register the handle if it supports
async access.
This function is almost identical to
createProcess. The only differences are:
Handles provided via UseHandle are not closed automatically.
This function takes an extra String argument to be used in creating
error messages.
This function has been available from the System.Process.Internals module
for some time, and is part of the System.Process module since version
1.2.1.0.
The name of an executable with a list of arguments
The FilePath argument names the executable, and is interpreted
according to the platform's standard policy for searching for
executables. Specifically:
on Unix systems the
execvp(3)
semantics is used, where if the executable filename does not
contain a slash (/) then the PATH environment variable is
searched for the executable.
on Windows systems the Win32 CreateProcess semantics is used.
Briefly: if the filename does not contain a path, then the
directory containing the parent executable is searched, followed
by the current directory, then some standard locations, and
finally the current PATH. An .exe extension is added if the
filename does not already have an extension. For full details
see the
documentation
for the Windows SearchPath API.
Windows does not have a mechanism for passing multiple arguments.
When using RawCommand on Windows, the command line is serialised
into a string, with arguments quoted separately. Command line
parsing is up individual programs, so the default behaviour may
not work for some programs. If you are not getting the desired
results, construct the command line yourself and use ShellCommand.
Instances3Eq, Show, IsString
EqCmdSpecDefined in process-1.6.26.1 · System.Process.Common
ShowCmdSpecDefined in process-1.6.26.1 · System.Process.Common
IsStringCmdSpecDefined in process-1.6.26.1 · System.Process.Common
Executable & arguments, or shell command. If cwd is Nothing, relative paths are resolved with respect to the current working directory. If cwd is provided, it is implementation-dependent whether relative paths are resolved with respect to cwd or the current working directory, so absolute paths should be used to ensure portability.
Close all file descriptors except stdin, stdout and stderr in the new process (on Windows, only works if std_in, std_out, and std_err are all Inherit). This implementation will call close on every fd from 3 to the maximum of open files, which can be slow for high maximum of open files.
On Windows systems this flag indicates that we should wait for the entire process tree
to finish before unblocking. On POSIX systems this flag is ignored. See $exec-on-windows for details.
Default: False
Instances2Eq, Show
EqCreateProcessDefined in process-1.6.26.1 · System.Process.Common
ShowCreateProcessDefined in process-1.6.26.1 · System.Process.Common
A handle to a process, which can be used to wait for termination
of the process using waitForProcess.
None of the process-creation functions in this library wait for
termination: they all return a ProcessHandle which may be used
to wait for the process later.
On Windows a second wait method can be used to block for event
completion. This requires two handles. A process job handle and
a events handle to monitor.
Close the stream's file descriptor without
passing a Handle. On POSIX systems this may
lead to strange behavior in the child process
because attempting to read or write after the
file has been closed throws an error. This
should only be used with child processes that
don't use the file descriptor at all. If you
wish to ignore the child process's output you
should either create a pipe and drain it
manually or pass a Handle that writes to
/dev/null.
Instances2Eq, Show
EqStdStreamDefined in process-1.6.26.1 · System.Process.Common
ShowStdStreamDefined in process-1.6.26.1 · System.Process.Common