<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>System.Process</title><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean" /><script src="haddock-util.js" type="text/javascript"></script><script type="text/javascript">//<![CDATA[ window.onload = function () {pageLoad();setSynopsis("mini_System-Process.html");}; //]]> </script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">process-1.1.0.1: Process libraries</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Portability</th><td>non-portable (requires concurrency)</td></tr><tr><th>Stability</th><td>experimental</td></tr><tr><th>Maintainer</th><td>libraries@haskell.org</td></tr><tr><th>Safe Haskell</th><td>Trustworthy</td></tr></table><p class="caption">System.Process</p></div><div id="table-of-contents"><p class="caption">Contents</p><ul><li><a href="#g:1">Running sub-processes </a><ul><li><a href="#g:2">Specific variants of createProcess </a></li></ul></li><li><a href="#g:3">Process completion </a></li></ul></div><div id="description"><p class="caption">Description</p><div class="doc"><p>Operations for creating and interacting with sub-processes. </p></div></div><div id="synopsis"><p id="control.syn" class="caption expander" onclick="toggleSection('syn')">Synopsis</p><ul id="section.syn" class="hide" onclick="toggleSection('syn')"><li class="src short"><a href="#v:createProcess">createProcess</a> :: <a href="System-Process.html#t:CreateProcess">CreateProcess</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> (<a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a>, <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a>, <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a>, <a href="System-Process.html#t:ProcessHandle">ProcessHandle</a>)</li><li class="src short"><a href="#v:shell">shell</a> :: <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> -> <a href="System-Process.html#t:CreateProcess">CreateProcess</a></li><li class="src short"><a href="#v:proc">proc</a> :: <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a> -> [<a href="../base-4.5.1.0/Data-String.html#t:String">String</a>] -> <a href="System-Process.html#t:CreateProcess">CreateProcess</a></li><li class="src short"><span class="keyword">data</span> <a href="#t:CreateProcess">CreateProcess</a> = <a href="#v:CreateProcess">CreateProcess</a> {<ul class="subs"><li><a href="#v:cmdspec">cmdspec</a> :: <a href="System-Process.html#t:CmdSpec">CmdSpec</a></li><li><a href="#v:cwd">cwd</a> :: <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a></li><li><a href="#v:env">env</a> :: <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> [(<a href="../base-4.5.1.0/Data-String.html#t:String">String</a>, <a href="../base-4.5.1.0/Data-String.html#t:String">String</a>)]</li><li><a href="#v:std_in">std_in</a> :: <a href="System-Process.html#t:StdStream">StdStream</a></li><li><a href="#v:std_out">std_out</a> :: <a href="System-Process.html#t:StdStream">StdStream</a></li><li><a href="#v:std_err">std_err</a> :: <a href="System-Process.html#t:StdStream">StdStream</a></li><li><a href="#v:close_fds">close_fds</a> :: <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a></li><li><a href="#v:create_group">create_group</a> :: <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a></li></ul>}</li><li class="src short"><span class="keyword">data</span> <a href="#t:CmdSpec">CmdSpec</a> <ul class="subs"><li>= <a href="#v:ShellCommand">ShellCommand</a> <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> </li><li>| <a href="#v:RawCommand">RawCommand</a> <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a> [<a href="../base-4.5.1.0/Data-String.html#t:String">String</a>] </li></ul></li><li class="src short"><span class="keyword">data</span> <a href="#t:StdStream">StdStream</a> <ul class="subs"><li>= <a href="#v:Inherit">Inherit</a> </li><li>| <a href="#v:UseHandle">UseHandle</a> <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a> </li><li>| <a href="#v:CreatePipe">CreatePipe</a> </li></ul></li><li class="src short"><span class="keyword">data</span> <a href="#t:ProcessHandle">ProcessHandle</a> </li><li class="src short"><a href="#v:runCommand">runCommand</a> :: <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="System-Process.html#t:ProcessHandle">ProcessHandle</a></li><li class="src short"><a href="#v:runProcess">runProcess</a> :: <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a> -> [<a href="../base-4.5.1.0/Data-String.html#t:String">String</a>] -> <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a> -> <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> [(<a href="../base-4.5.1.0/Data-String.html#t:String">String</a>, <a href="../base-4.5.1.0/Data-String.html#t:String">String</a>)] -> <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a> -> <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a> -> <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="System-Process.html#t:ProcessHandle">ProcessHandle</a></li><li class="src short"><a href="#v:runInteractiveCommand">runInteractiveCommand</a> :: <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> (<a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a>, <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a>, <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a>, <a href="System-Process.html#t:ProcessHandle">ProcessHandle</a>)</li><li class="src short"><a href="#v:runInteractiveProcess">runInteractiveProcess</a> :: <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a> -> [<a href="../base-4.5.1.0/Data-String.html#t:String">String</a>] -> <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a> -> <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> [(<a href="../base-4.5.1.0/Data-String.html#t:String">String</a>, <a href="../base-4.5.1.0/Data-String.html#t:String">String</a>)] -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> (<a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a>, <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a>, <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a>, <a href="System-Process.html#t:ProcessHandle">ProcessHandle</a>)</li><li class="src short"><a href="#v:readProcess">readProcess</a> :: <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a> -> [<a href="../base-4.5.1.0/Data-String.html#t:String">String</a>] -> <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="../base-4.5.1.0/Data-String.html#t:String">String</a></li><li class="src short"><a href="#v:readProcessWithExitCode">readProcessWithExitCode</a> :: <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a> -> [<a href="../base-4.5.1.0/Data-String.html#t:String">String</a>] -> <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> (<a href="../base-4.5.1.0/System-Exit.html#t:ExitCode">ExitCode</a>, <a href="../base-4.5.1.0/Data-String.html#t:String">String</a>, <a href="../base-4.5.1.0/Data-String.html#t:String">String</a>)</li><li class="src short"><a href="#v:system">system</a> :: <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="../base-4.5.1.0/System-Exit.html#t:ExitCode">ExitCode</a></li><li class="src short"><a href="#v:rawSystem">rawSystem</a> :: <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> -> [<a href="../base-4.5.1.0/Data-String.html#t:String">String</a>] -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="../base-4.5.1.0/System-Exit.html#t:ExitCode">ExitCode</a></li><li class="src short"><a href="#v:showCommandForUser">showCommandForUser</a> :: <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a> -> [<a href="../base-4.5.1.0/Data-String.html#t:String">String</a>] -> <a href="../base-4.5.1.0/Data-String.html#t:String">String</a></li><li class="src short"><a href="#v:waitForProcess">waitForProcess</a> :: <a href="System-Process.html#t:ProcessHandle">ProcessHandle</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="../base-4.5.1.0/System-Exit.html#t:ExitCode">ExitCode</a></li><li class="src short"><a href="#v:getProcessExitCode">getProcessExitCode</a> :: <a href="System-Process.html#t:ProcessHandle">ProcessHandle</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> (<a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="../base-4.5.1.0/System-Exit.html#t:ExitCode">ExitCode</a>)</li><li class="src short"><a href="#v:terminateProcess">terminateProcess</a> :: <a href="System-Process.html#t:ProcessHandle">ProcessHandle</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:interruptProcessGroupOf">interruptProcessGroupOf</a> :: <a href="System-Process.html#t:ProcessHandle">ProcessHandle</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> ()</li></ul></div><div id="interface"><h1 id="g:1">Running sub-processes </h1><div class="top"><p class="src"><a name="v:createProcess" class="def">createProcess</a> :: <a href="System-Process.html#t:CreateProcess">CreateProcess</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> (<a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a>, <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a>, <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a>, <a href="System-Process.html#t:ProcessHandle">ProcessHandle</a>)</p><div class="doc"><p>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 <code><a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a></code>s, or just inherited from the parent (the default.) </p><p>The details of how to create the process are passed in the <code><a href="System-Process.html#t:CreateProcess">CreateProcess</a></code> record. To make it easier to construct a <code><a href="System-Process.html#t:CreateProcess">CreateProcess</a></code>, the functions <code><a href="System-Process.html#v:proc">proc</a></code> and <code><a href="System-Process.html#v:shell">shell</a></code> are supplied that fill in the fields with default values which can be overriden as needed. </p><p><code><a href="System-Process.html#v:createProcess">createProcess</a></code> returns <code>(mb_stdin_hdl, mb_stdout_hdl, mb_stderr_hdl, p)</code>, where </p><ul><li> if <code>std_in == CreatePipe</code>, then <code>mb_stdin_hdl</code> will be <code>Just h</code>, where <code>h</code> is the write end of the pipe connected to the child process's <code>stdin</code>. </li><li> otherwise, <code>mb_stdin_hdl == Nothing</code> </li></ul><p>Similarly for <code>mb_stdout_hdl</code> and <code>mb_stderr_hdl</code>. </p><p>For example, to execute a simple <code>ls</code> command: </p><pre> r <- createProcess (proc "ls" []) </pre><p>To create a pipe from which to read the output of <code>ls</code>: </p><pre> (_, Just hout, _, _) <- createProcess (proc "ls" []){ std_out = CreatePipe } </pre><p>To also set the directory in which to run <code>ls</code>: </p><pre> (_, Just hout, _, _) <- createProcess (proc "ls" []){ cwd = Just "\home\bob", std_out = CreatePipe } </pre></div></div><div class="top"><p class="src"><a name="v:shell" class="def">shell</a> :: <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> -> <a href="System-Process.html#t:CreateProcess">CreateProcess</a></p><div class="doc"><p>Construct a <code><a href="System-Process.html#t:CreateProcess">CreateProcess</a></code> record for passing to <code><a href="System-Process.html#v:createProcess">createProcess</a></code>, representing a command to be passed to the shell. </p></div></div><div class="top"><p class="src"><a name="v:proc" class="def">proc</a> :: <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a> -> [<a href="../base-4.5.1.0/Data-String.html#t:String">String</a>] -> <a href="System-Process.html#t:CreateProcess">CreateProcess</a></p><div class="doc"><p>Construct a <code><a href="System-Process.html#t:CreateProcess">CreateProcess</a></code> record for passing to <code><a href="System-Process.html#v:createProcess">createProcess</a></code>, representing a raw command with arguments. </p></div></div><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:CreateProcess" class="def">CreateProcess</a> </p><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:CreateProcess" class="def">CreateProcess</a></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div class="subs fields"><p class="caption">Fields</p><dl><dt class="src"><a name="v:cmdspec" class="def">cmdspec</a> :: <a href="System-Process.html#t:CmdSpec">CmdSpec</a></dt><dd class="doc"><p>Executable & arguments, or shell command </p></dd><dt class="src"><a name="v:cwd" class="def">cwd</a> :: <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a></dt><dd class="doc"><p>Optional path to the working directory for the new process </p></dd><dt class="src"><a name="v:env" class="def">env</a> :: <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> [(<a href="../base-4.5.1.0/Data-String.html#t:String">String</a>, <a href="../base-4.5.1.0/Data-String.html#t:String">String</a>)]</dt><dd class="doc"><p>Optional environment (otherwise inherit from the current process) </p></dd><dt class="src"><a name="v:std_in" class="def">std_in</a> :: <a href="System-Process.html#t:StdStream">StdStream</a></dt><dd class="doc"><p>How to determine stdin </p></dd><dt class="src"><a name="v:std_out" class="def">std_out</a> :: <a href="System-Process.html#t:StdStream">StdStream</a></dt><dd class="doc"><p>How to determine stdout </p></dd><dt class="src"><a name="v:std_err" class="def">std_err</a> :: <a href="System-Process.html#t:StdStream">StdStream</a></dt><dd class="doc"><p>How to determine stderr </p></dd><dt class="src"><a name="v:close_fds" class="def">close_fds</a> :: <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a></dt><dd class="doc"><p>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) </p></dd><dt class="src"><a name="v:create_group" class="def">create_group</a> :: <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a></dt><dd class="doc"><p>Create a new process group </p></dd></dl><div class="clear"></div></div></td></tr></table></div></div><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:CmdSpec" class="def">CmdSpec</a> </p><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:ShellCommand" class="def">ShellCommand</a> <a href="../base-4.5.1.0/Data-String.html#t:String">String</a></td><td class="doc"><p>a command line to execute using the shell </p></td></tr><tr><td class="src"><a name="v:RawCommand" class="def">RawCommand</a> <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a> [<a href="../base-4.5.1.0/Data-String.html#t:String">String</a>]</td><td class="doc"><p>the filename of an executable with a list of arguments </p></td></tr></table></div></div><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:StdStream" class="def">StdStream</a> </p><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:Inherit" class="def">Inherit</a></td><td class="doc"><p>Inherit Handle from parent </p></td></tr><tr><td class="src"><a name="v:UseHandle" class="def">UseHandle</a> <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a></td><td class="doc"><p>Use the supplied Handle </p></td></tr><tr><td class="src"><a name="v:CreatePipe" class="def">CreatePipe</a></td><td class="doc"><p>Create a new pipe. The returned <code>Handle</code> will use the default encoding and newline translation mode (just like <code>Handle</code>s created by <code>openFile</code>). </p></td></tr></table></div></div><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:ProcessHandle" class="def">ProcessHandle</a> </p></div><h2 id="g:2">Specific variants of createProcess </h2><div class="top"><p class="src"><a name="v:runCommand" class="def">runCommand</a> :: <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="System-Process.html#t:ProcessHandle">ProcessHandle</a></p><div class="doc"><p>Runs a command using the shell. </p></div></div><div class="top"><p class="src"><a name="v:runProcess" class="def">runProcess</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a></td><td class="doc"><p>Filename of the executable </p></td></tr><tr><td class="src">-> [<a href="../base-4.5.1.0/Data-String.html#t:String">String</a>]</td><td class="doc"><p>Arguments to pass to the executable </p></td></tr><tr><td class="src">-> <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a></td><td class="doc"><p>Optional path to the working directory </p></td></tr><tr><td class="src">-> <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> [(<a href="../base-4.5.1.0/Data-String.html#t:String">String</a>, <a href="../base-4.5.1.0/Data-String.html#t:String">String</a>)]</td><td class="doc"><p>Optional environment (otherwise inherit) </p></td></tr><tr><td class="src">-> <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a></td><td class="doc"><p>Handle to use for <code>stdin</code> (Nothing => use existing <code>stdin</code>) </p></td></tr><tr><td class="src">-> <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a></td><td class="doc"><p>Handle to use for <code>stdout</code> (Nothing => use existing <code>stdout</code>) </p></td></tr><tr><td class="src">-> <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a></td><td class="doc"><p>Handle to use for <code>stderr</code> (Nothing => use existing <code>stderr</code>) </p></td></tr><tr><td class="src">-> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="System-Process.html#t:ProcessHandle">ProcessHandle</a></td><td class="doc empty"> </td></tr></table></div><div class="doc"><p>Runs a raw command, optionally specifying <code><a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a></code>s from which to take the <code>stdin</code>, <code>stdout</code> and <code>stderr</code> channels for the new process (otherwise these handles are inherited from the current process). </p><p>Any <code><a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a></code>s passed to <code><a href="System-Process.html#v:runProcess">runProcess</a></code> are placed immediately in the closed state. </p><p>Note: consider using the more general <code><a href="System-Process.html#v:createProcess">createProcess</a></code> instead of <code><a href="System-Process.html#v:runProcess">runProcess</a></code>. </p></div></div><div class="top"><p class="src"><a name="v:runInteractiveCommand" class="def">runInteractiveCommand</a> :: <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> (<a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a>, <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a>, <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a>, <a href="System-Process.html#t:ProcessHandle">ProcessHandle</a>)</p><div class="doc"><p>Runs a command using the shell, and returns <code><a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a></code>s that may be used to communicate with the process via its <code>stdin</code>, <code>stdout</code>, and <code>stderr</code> respectively. The <code><a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a></code>s are initially in binary mode; if you need them to be in text mode then use <code><a href="../base-4.5.1.0/GHC-IO-Handle.html#v:hSetBinaryMode">hSetBinaryMode</a></code>. </p></div></div><div class="top"><p class="src"><a name="v:runInteractiveProcess" class="def">runInteractiveProcess</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a></td><td class="doc"><p>Filename of the executable </p></td></tr><tr><td class="src">-> [<a href="../base-4.5.1.0/Data-String.html#t:String">String</a>]</td><td class="doc"><p>Arguments to pass to the executable </p></td></tr><tr><td class="src">-> <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a></td><td class="doc"><p>Optional path to the working directory </p></td></tr><tr><td class="src">-> <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> [(<a href="../base-4.5.1.0/Data-String.html#t:String">String</a>, <a href="../base-4.5.1.0/Data-String.html#t:String">String</a>)]</td><td class="doc"><p>Optional environment (otherwise inherit) </p></td></tr><tr><td class="src">-> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> (<a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a>, <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a>, <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a>, <a href="System-Process.html#t:ProcessHandle">ProcessHandle</a>)</td><td class="doc empty"> </td></tr></table></div><div class="doc"><p>Runs a raw command, and returns <code><a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a></code>s that may be used to communicate with the process via its <code>stdin</code>, <code>stdout</code> and <code>stderr</code> respectively. </p><p>For example, to start a process and feed a string to its stdin: </p><pre> (inp,out,err,pid) <- runInteractiveProcess "..." forkIO (hPutStr inp str) </pre><p>The <code><a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a></code>s are initially in binary mode; if you need them to be in text mode then use <code><a href="../base-4.5.1.0/GHC-IO-Handle.html#v:hSetBinaryMode">hSetBinaryMode</a></code>. </p></div></div><div class="top"><p class="src"><a name="v:readProcess" class="def">readProcess</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a></td><td class="doc"><p>command to run </p></td></tr><tr><td class="src">-> [<a href="../base-4.5.1.0/Data-String.html#t:String">String</a>]</td><td class="doc"><p>any arguments </p></td></tr><tr><td class="src">-> <a href="../base-4.5.1.0/Data-String.html#t:String">String</a></td><td class="doc"><p>standard input </p></td></tr><tr><td class="src">-> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="../base-4.5.1.0/Data-String.html#t:String">String</a></td><td class="doc"><p>stdout </p></td></tr></table></div><div class="doc"><p>readProcess forks an external process, reads its standard output strictly, blocking until the process terminates, and returns the output string. </p><p>Output is returned strictly, so this is not suitable for interactive applications. </p><p>This function throws an <code><a href="../base-4.5.1.0/System-IO-Error.html#t:IOError">IOError</a></code> if the process <code><a href="../base-4.5.1.0/System-Exit.html#t:ExitCode">ExitCode</a></code> is anything other than <code><a href="../base-4.5.1.0/System-Exit.html#v:ExitSuccess">ExitSuccess</a></code>. </p><p>Users of this function should compile with <code>-threaded</code> if they want other Haskell threads to keep running while waiting on the result of readProcess. </p><pre> > readProcess "date" [] [] "Thu Feb 7 10:03:39 PST 2008\n" </pre><p>The arguments are: </p><ul><li> The command to run, which must be in the $PATH, or an absolute path </li><li> A list of separate command line arguments to the program </li><li> A string to pass on the standard input to the program. </li></ul></div></div><div class="top"><p class="src"><a name="v:readProcessWithExitCode" class="def">readProcessWithExitCode</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a></td><td class="doc"><p>command to run </p></td></tr><tr><td class="src">-> [<a href="../base-4.5.1.0/Data-String.html#t:String">String</a>]</td><td class="doc"><p>any arguments </p></td></tr><tr><td class="src">-> <a href="../base-4.5.1.0/Data-String.html#t:String">String</a></td><td class="doc"><p>standard input </p></td></tr><tr><td class="src">-> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> (<a href="../base-4.5.1.0/System-Exit.html#t:ExitCode">ExitCode</a>, <a href="../base-4.5.1.0/Data-String.html#t:String">String</a>, <a href="../base-4.5.1.0/Data-String.html#t:String">String</a>)</td><td class="doc"><p>exitcode, stdout, stderr </p></td></tr></table></div><div class="doc"><p>readProcessWithExitCode creates an external process, reads its standard output and standard error strictly, waits until the process terminates, and then returns the <code><a href="../base-4.5.1.0/System-Exit.html#t:ExitCode">ExitCode</a></code> of the process, the standard output, and the standard error. </p><p><code><a href="System-Process.html#v:readProcess">readProcess</a></code> and <code><a href="System-Process.html#v:readProcessWithExitCode">readProcessWithExitCode</a></code> are fairly simple wrappers around <code><a href="System-Process.html#v:createProcess">createProcess</a></code>. Constructing variants of these functions is quite easy: follow the link to the source code to see how <code><a href="System-Process.html#v:readProcess">readProcess</a></code> is implemented. </p></div></div><div class="top"><p class="src"><a name="v:system" class="def">system</a> :: <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="../base-4.5.1.0/System-Exit.html#t:ExitCode">ExitCode</a></p><div class="doc"><p>Computation <code>system cmd</code> returns the exit code produced when the operating system runs the shell command <code>cmd</code>. </p><p>This computation may fail with </p><ul><li> <code>PermissionDenied</code>: The process has insufficient privileges to perform the operation. </li><li> <code>ResourceExhausted</code>: Insufficient resources are available to perform the operation. </li><li> <code>UnsupportedOperation</code>: The implementation does not support system calls. </li></ul><p>On Windows, <code><a href="System-Process.html#v:system">system</a></code> passes the command to the Windows command interpreter (<code>CMD.EXE</code> or <code>COMMAND.COM</code>), hence Unixy shell tricks will not work. </p></div></div><div class="top"><p class="src"><a name="v:rawSystem" class="def">rawSystem</a> :: <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> -> [<a href="../base-4.5.1.0/Data-String.html#t:String">String</a>] -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="../base-4.5.1.0/System-Exit.html#t:ExitCode">ExitCode</a></p><div class="doc"><p>The computation <code><code><a href="System-Process.html#v:rawSystem">rawSystem</a></code> cmd args</code> runs the operating system command <code>cmd</code> in such a way that it receives as arguments the <code>args</code> strings exactly as given, with no funny escaping or shell meta-syntax expansion. It will therefore behave more portably between operating systems than <code><a href="System-Process.html#v:system">system</a></code>. </p><p>The return codes and possible failures are the same as for <code><a href="System-Process.html#v:system">system</a></code>. </p></div></div><div class="top"><p class="src"><a name="v:showCommandForUser" class="def">showCommandForUser</a> :: <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a> -> [<a href="../base-4.5.1.0/Data-String.html#t:String">String</a>] -> <a href="../base-4.5.1.0/Data-String.html#t:String">String</a></p><div class="doc"><p>Given a program <code>p</code> and arguments <code>args</code>, <code>showCommandForUser p args</code> returns a string suitable for pasting into sh (on POSIX OSs) or cmd.exe (on Windows). </p></div></div><h1 id="g:3">Process completion </h1><div class="top"><p class="src"><a name="v:waitForProcess" class="def">waitForProcess</a> :: <a href="System-Process.html#t:ProcessHandle">ProcessHandle</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="../base-4.5.1.0/System-Exit.html#t:ExitCode">ExitCode</a></p><div class="doc"><p>Waits for the specified process to terminate, and returns its exit code. </p><p>GHC Note: in order to call <code>waitForProcess</code> without blocking all the other threads in the system, you must compile the program with <code>-threaded</code>. </p></div></div><div class="top"><p class="src"><a name="v:getProcessExitCode" class="def">getProcessExitCode</a> :: <a href="System-Process.html#t:ProcessHandle">ProcessHandle</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> (<a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="../base-4.5.1.0/System-Exit.html#t:ExitCode">ExitCode</a>)</p><div class="doc"><p>This is a non-blocking version of <code><a href="System-Process.html#v:waitForProcess">waitForProcess</a></code>. If the process is still running, <code><a href="../base-4.5.1.0/Data-Maybe.html#v:Nothing">Nothing</a></code> is returned. If the process has exited, then <code><code><a href="../base-4.5.1.0/Data-Maybe.html#v:Just">Just</a></code> e</code> is returned where <code>e</code> is the exit code of the process. </p></div></div><div class="top"><p class="src"><a name="v:terminateProcess" class="def">terminateProcess</a> :: <a href="System-Process.html#t:ProcessHandle">ProcessHandle</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> ()</p><div class="doc"><p>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 <code><a href="System-Process.html#v:getProcessExitCode">getProcessExitCode</a></code>. </p><p>On Unix systems, <code><a href="System-Process.html#v:terminateProcess">terminateProcess</a></code> sends the process the SIGTERM signal. On Windows systems, the Win32 <code>TerminateProcess</code> function is called, passing an exit code of 1. </p><p>Note: on Windows, if the process was a shell command created by <code><a href="System-Process.html#v:createProcess">createProcess</a></code> with <code><a href="System-Process.html#v:shell">shell</a></code>, or created by <code><a href="System-Process.html#v:runCommand">runCommand</a></code> or <code><a href="System-Process.html#v:runInteractiveCommand">runInteractiveCommand</a></code>, then <code><a href="System-Process.html#v:terminateProcess">terminateProcess</a></code> will only terminate the shell, not the command itself. On Unix systems, both processes are in a process group and will be terminated together. </p></div></div><div class="top"><p class="src"><a name="v:interruptProcessGroupOf" class="def">interruptProcessGroupOf</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: <a href="System-Process.html#t:ProcessHandle">ProcessHandle</a></td><td class="doc"><p>A process in the process group </p></td></tr><tr><td class="src">-> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> ()</td><td class="doc empty"> </td></tr></table></div><div class="doc"><p>Sends an interrupt signal to the process group of the given process. </p><p>On Unix systems, it sends the group the SIGINT signal. </p><p>On Windows systems, it generates a CTRL_BREAK_EVENT and will only work for processes created using <code><a href="System-Process.html#v:createProcess">createProcess</a></code> and setting the <code><a href="System-Process.html#v:create_group">create_group</a></code> flag </p></div></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.11.0</p></div></body></html>