ocaml-containers/0.20/CCUnix.html
2016-10-14 13:43:14 +02:00

353 lines
No EOL
18 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<link rel="Start" href="index.html">
<link rel="previous" href="Containers_io_is_deprecated.html">
<link rel="next" href="CCSexp.html">
<link rel="Up" href="index.html">
<link title="Index of types" rel=Appendix href="index_types.html">
<link title="Index of exceptions" rel=Appendix href="index_exceptions.html">
<link title="Index of values" rel=Appendix href="index_values.html">
<link title="Index of class methods" rel=Appendix href="index_methods.html">
<link title="Index of class types" rel=Appendix href="index_class_types.html">
<link title="Index of modules" rel=Appendix href="index_modules.html">
<link title="Index of module types" rel=Appendix href="index_module_types.html">
<link title="CCVector" rel="Chapter" href="CCVector.html">
<link title="CCPrint" rel="Chapter" href="CCPrint.html">
<link title="CCError" rel="Chapter" href="CCError.html">
<link title="CCHeap" rel="Chapter" href="CCHeap.html">
<link title="CCList" rel="Chapter" href="CCList.html">
<link title="CCOpt" rel="Chapter" href="CCOpt.html">
<link title="CCPair" rel="Chapter" href="CCPair.html">
<link title="CCFun" rel="Chapter" href="CCFun.html">
<link title="CCHash" rel="Chapter" href="CCHash.html">
<link title="CCInt" rel="Chapter" href="CCInt.html">
<link title="CCBool" rel="Chapter" href="CCBool.html">
<link title="CCFloat" rel="Chapter" href="CCFloat.html">
<link title="CCArray" rel="Chapter" href="CCArray.html">
<link title="CCRef" rel="Chapter" href="CCRef.html">
<link title="CCSet" rel="Chapter" href="CCSet.html">
<link title="CCOrd" rel="Chapter" href="CCOrd.html">
<link title="CCRandom" rel="Chapter" href="CCRandom.html">
<link title="CCString" rel="Chapter" href="CCString.html">
<link title="CCHashtbl" rel="Chapter" href="CCHashtbl.html">
<link title="CCMap" rel="Chapter" href="CCMap.html">
<link title="CCFormat" rel="Chapter" href="CCFormat.html">
<link title="CCIO" rel="Chapter" href="CCIO.html">
<link title="CCInt64" rel="Chapter" href="CCInt64.html">
<link title="CCChar" rel="Chapter" href="CCChar.html">
<link title="CCResult" rel="Chapter" href="CCResult.html">
<link title="Containers" rel="Chapter" href="Containers.html">
<link title="CCKTree" rel="Chapter" href="CCKTree.html">
<link title="CCKList" rel="Chapter" href="CCKList.html">
<link title="CCLazy_list" rel="Chapter" href="CCLazy_list.html">
<link title="CCMultiMap" rel="Chapter" href="CCMultiMap.html">
<link title="CCMultiSet" rel="Chapter" href="CCMultiSet.html">
<link title="CCTrie" rel="Chapter" href="CCTrie.html">
<link title="CCFlatHashtbl" rel="Chapter" href="CCFlatHashtbl.html">
<link title="CCCache" rel="Chapter" href="CCCache.html">
<link title="CCPersistentHashtbl" rel="Chapter" href="CCPersistentHashtbl.html">
<link title="CCDeque" rel="Chapter" href="CCDeque.html">
<link title="CCFQueue" rel="Chapter" href="CCFQueue.html">
<link title="CCBV" rel="Chapter" href="CCBV.html">
<link title="CCMixtbl" rel="Chapter" href="CCMixtbl.html">
<link title="CCMixmap" rel="Chapter" href="CCMixmap.html">
<link title="CCRingBuffer" rel="Chapter" href="CCRingBuffer.html">
<link title="CCIntMap" rel="Chapter" href="CCIntMap.html">
<link title="CCPersistentArray" rel="Chapter" href="CCPersistentArray.html">
<link title="CCMixset" rel="Chapter" href="CCMixset.html">
<link title="CCHashconsedSet" rel="Chapter" href="CCHashconsedSet.html">
<link title="CCGraph" rel="Chapter" href="CCGraph.html">
<link title="CCHashSet" rel="Chapter" href="CCHashSet.html">
<link title="CCBitField" rel="Chapter" href="CCBitField.html">
<link title="CCHashTrie" rel="Chapter" href="CCHashTrie.html">
<link title="CCBloom" rel="Chapter" href="CCBloom.html">
<link title="CCWBTree" rel="Chapter" href="CCWBTree.html">
<link title="CCRAL" rel="Chapter" href="CCRAL.html">
<link title="CCAllocCache" rel="Chapter" href="CCAllocCache.html">
<link title="CCImmutArray" rel="Chapter" href="CCImmutArray.html">
<link title="CCHet" rel="Chapter" href="CCHet.html">
<link title="Containers_string" rel="Chapter" href="Containers_string.html">
<link title="CCKMP" rel="Chapter" href="CCKMP.html">
<link title="CCLevenshtein" rel="Chapter" href="CCLevenshtein.html">
<link title="CCApp_parse" rel="Chapter" href="CCApp_parse.html">
<link title="CCParse" rel="Chapter" href="CCParse.html">
<link title="CCBigstring" rel="Chapter" href="CCBigstring.html">
<link title="CCArray1" rel="Chapter" href="CCArray1.html">
<link title="CCPool" rel="Chapter" href="CCPool.html">
<link title="CCLock" rel="Chapter" href="CCLock.html">
<link title="CCSemaphore" rel="Chapter" href="CCSemaphore.html">
<link title="CCThread" rel="Chapter" href="CCThread.html">
<link title="CCBlockingQueue" rel="Chapter" href="CCBlockingQueue.html">
<link title="CCTimer" rel="Chapter" href="CCTimer.html">
<link title="Containers_advanced" rel="Chapter" href="Containers_advanced.html">
<link title="CCLinq" rel="Chapter" href="CCLinq.html">
<link title="CCBatch" rel="Chapter" href="CCBatch.html">
<link title="CCCat" rel="Chapter" href="CCCat.html">
<link title="CCMonadIO" rel="Chapter" href="CCMonadIO.html">
<link title="Containers_io_is_deprecated" rel="Chapter" href="Containers_io_is_deprecated.html">
<link title="CCUnix" rel="Chapter" href="CCUnix.html">
<link title="CCSexp" rel="Chapter" href="CCSexp.html">
<link title="CCSexpM" rel="Chapter" href="CCSexpM.html"><link title="Calling Commands" rel="Section" href="#2_CallingCommands">
<link title="Accessors" rel="Section" href="#2_Accessors">
<link title="Simple IO" rel="Section" href="#2_SimpleIO">
<link title="Infix Functions" rel="Section" href="#2_InfixFunctions">
<title>Containers doc : CCUnix</title>
</head>
<body>
<div class="navbar"><a class="pre" href="Containers_io_is_deprecated.html" title="Containers_io_is_deprecated">Previous</a>
&nbsp;<a class="up" href="index.html" title="Index">Up</a>
&nbsp;<a class="post" href="CCSexp.html" title="CCSexp">Next</a>
</div>
<h1>Module <a href="type_CCUnix.html">CCUnix</a></h1>
<pre><span class="keyword">module</span> CCUnix: <code class="code"><span class="keyword">sig</span></code> <a href="CCUnix.html">..</a> <code class="code"><span class="keyword">end</span></code></pre><div class="info module top">
<h1 id="1_HighlevelFunctionsontopofUnix">High-level Functions on top of Unix</h1>
<p>
Some useful functions built on top of Unix.
<p>
<b>status: unstable</b><br>
<b>Since</b> 0.10<br>
</div>
<hr width="100%">
<pre><span id="TYPEor_error"><span class="keyword">type</span> <code class="type">'a</code> or_error</span> = <code class="type">[ `Error of string | `Ok of 'a ]</code> </pre>
<pre><span id="TYPEgen"><span class="keyword">type</span> <code class="type">'a</code> gen</span> = <code class="type">unit -> 'a option</code> </pre>
<br>
<h2 id="2_CallingCommands">Calling Commands</h2><br>
<pre><span id="VALescape_str"><span class="keyword">val</span> escape_str</span> : <code class="type">Buffer.t -> string -> unit</code></pre><div class="info ">
Escape a string so it can be a shell argument.<br>
</div>
<pre><span id="TYPEcall_result"><span class="keyword">type</span> <code class="type"></code>call_result</span> = &lt;</pre><table class="typetable">
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTcall_result.errcode">errcode</span>&nbsp;: <code class="type">int</code>;</code></td>
<td class="typefieldcomment" align="left" valign="top" ><code>(*</code></td><td class="typefieldcomment" align="left" valign="top" ><div class="info ">
Extracted from status<br>
</div>
</td><td class="typefieldcomment" align="left" valign="bottom" ><code>*)</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTcall_result.status">status</span>&nbsp;: <code class="type">Unix.process_status</code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTcall_result.stderr">stderr</span>&nbsp;: <code class="type">string</code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTcall_result.stdout">stdout</span>&nbsp;: <code class="type">string</code>;</code></td>
</tr></table>
>
</pre>
<pre><span id="VALcall"><span class="keyword">val</span> call</span> : <code class="type">?bufsize:int -><br> ?stdin:[ `Gen of string <a href="CCUnix.html#TYPEgen">gen</a> | `Str of string ] -><br> ?env:string array -><br> ('a, Buffer.t, unit, <a href="CCUnix.html#TYPEcall_result">call_result</a>) Pervasives.format4 -> 'a</code></pre><div class="info ">
<code class="code">call cmd</code> wraps the result of <code class="code"><span class="constructor">Unix</span>.open_process_full cmd</code> into an
object. It reads the full stdout and stderr of the subprocess before
returning.<br>
</div>
<div class="param_info"><code class="code">bufsize</code> : buffer size used to read stdout and stderr</div>
<div class="param_info"><code class="code">stdin</code> : if provided, the generator or string is consumed and fed to
the subprocess input channel, which is then closed.</div>
<div class="param_info"><code class="code">env</code> : environment to run the command in</div>
<pre><span id="TYPEline"><span class="keyword">type</span> <code class="type"></code>line</span> = <code class="type">string</code> </pre>
<pre><span id="TYPEasync_call_result"><span class="keyword">type</span> <code class="type"></code>async_call_result</span> = &lt;</pre><table class="typetable">
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTasync_call_result.close_all">close_all</span>&nbsp;: <code class="type">unit</code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTasync_call_result.close_err">close_err</span>&nbsp;: <code class="type">unit</code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTasync_call_result.close_in">close_in</span>&nbsp;: <code class="type">unit</code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTasync_call_result.close_out">close_out</span>&nbsp;: <code class="type">unit</code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTasync_call_result.stderr">stderr</span>&nbsp;: <code class="type"><a href="CCUnix.html#TYPEline">line</a> <a href="CCUnix.html#TYPEgen">gen</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTasync_call_result.stdin">stdin</span>&nbsp;: <code class="type"><a href="CCUnix.html#TYPEline">line</a> -> unit</code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTasync_call_result.stdout">stdout</span>&nbsp;: <code class="type"><a href="CCUnix.html#TYPEline">line</a> <a href="CCUnix.html#TYPEgen">gen</a></code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTasync_call_result.wait">wait</span>&nbsp;: <code class="type">Unix.process_status</code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTasync_call_result.wait_errcode">wait_errcode</span>&nbsp;: <code class="type">int</code>;</code></td>
</tr></table>
>
</pre>
<div class="info ">
A subprocess for interactive usage (read/write channels line by line)<br>
<b>Since</b> 0.11<br>
</div>
<pre><span id="VALasync_call"><span class="keyword">val</span> async_call</span> : <code class="type">?env:string array -><br> ('a, Buffer.t, unit, <a href="CCUnix.html#TYPEasync_call_result">async_call_result</a>) Pervasives.format4 -> 'a</code></pre><div class="info ">
Spawns a subprocess, like <a href="CCUnix.html#VALcall"><code class="code"><span class="constructor">CCUnix</span>.call</code></a>, but the subprocess's channels are
line generators and line sinks (for stdin).
if <code class="code">p</code> is <code class="code">async_call <span class="string">"cmd"</span></code>, then <code class="code">p<span class="keywordsign">#</span>wait</code> waits for the subprocess
to die. Channels can be closed independently.<br>
<b>Since</b> 0.11<br>
</div>
<br>
<h2 id="2_Accessors">Accessors</h2><br>
<pre><span id="VALstdout"><span class="keyword">val</span> stdout</span> : <code class="type">< stdout : 'a; .. > -> 'a</code></pre>
<pre><span id="VALstderr"><span class="keyword">val</span> stderr</span> : <code class="type">< stderr : 'a; .. > -> 'a</code></pre>
<pre><span id="VALstatus"><span class="keyword">val</span> status</span> : <code class="type">< status : 'a; .. > -> 'a</code></pre>
<pre><span id="VALerrcode"><span class="keyword">val</span> errcode</span> : <code class="type">< errcode : 'a; .. > -> 'a</code></pre><br>
<h2 id="2_SimpleIO">Simple IO</h2><br>
<pre><span id="VALwith_in"><span class="keyword">val</span> with_in</span> : <code class="type">?mode:int -><br> ?flags:Unix.open_flag list -> string -> f:(Pervasives.in_channel -> 'a) -> 'a</code></pre><div class="info ">
Open an input file with the given optional flag list, calls the function
on the input channel. When the function raises or returns, the
channel is closed.<br>
<b>Since</b> 0.16<br>
</div>
<div class="param_info"><code class="code">flags</code> : opening flags. <code class="code"><span class="constructor">Unix</span>.<span class="constructor">O_RDONLY</span></code> is used in any cases</div>
<pre><span id="VALwith_out"><span class="keyword">val</span> with_out</span> : <code class="type">?mode:int -><br> ?flags:Unix.open_flag list -><br> string -> f:(Pervasives.out_channel -> 'a) -> 'a</code></pre><div class="info ">
Same as <a href="CCUnix.html#VALwith_in"><code class="code"><span class="constructor">CCUnix</span>.with_in</code></a> but for an output channel<br>
<b>Since</b> 0.16<br>
</div>
<div class="param_info"><code class="code">flags</code> : opening flags (default <code class="code">[<span class="constructor">Unix</span>.<span class="constructor">O_CREAT</span>; <span class="constructor">Unix</span>.<span class="constructor">O_TRUNC</span>]</code>)
<code class="code"><span class="constructor">Unix</span>.<span class="constructor">O_WRONLY</span></code> is used in any cases.</div>
<pre><span id="VALwith_process_in"><span class="keyword">val</span> with_process_in</span> : <code class="type">string -> f:(Pervasives.in_channel -> 'a) -> 'a</code></pre><div class="info ">
Open a subprocess and obtain a handle to its stdout<br>
<b>Since</b> 0.16<br>
</div>
<pre><span id="VALwith_process_out"><span class="keyword">val</span> with_process_out</span> : <code class="type">string -> f:(Pervasives.out_channel -> 'a) -> 'a</code></pre><div class="info ">
Open a subprocess and obtain a handle to its stdin<br>
<b>Since</b> 0.16<br>
</div>
<pre><span id="TYPEprocess_full"><span class="keyword">type</span> <code class="type"></code>process_full</span> = &lt;</pre><table class="typetable">
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTprocess_full.close">close</span>&nbsp;: <code class="type">Unix.process_status</code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTprocess_full.stderr">stderr</span>&nbsp;: <code class="type">Pervasives.in_channel</code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTprocess_full.stdin">stdin</span>&nbsp;: <code class="type">Pervasives.out_channel</code>;</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTprocess_full.stdout">stdout</span>&nbsp;: <code class="type">Pervasives.in_channel</code>;</code></td>
</tr></table>
>
</pre>
<div class="info ">
Handle to a subprocess.<br>
<b>Since</b> 0.16<br>
</div>
<pre><span id="VALwith_process_full"><span class="keyword">val</span> with_process_full</span> : <code class="type">?env:string array -> string -> f:(<a href="CCUnix.html#TYPEprocess_full">process_full</a> -> 'a) -> 'a</code></pre><div class="info ">
Open a subprocess and obtain a handle to its channels.<br>
<b>Since</b> 0.16<br>
</div>
<div class="param_info"><code class="code">env</code> : environment to pass to the subprocess.</div>
<pre><span id="VALwith_connection"><span class="keyword">val</span> with_connection</span> : <code class="type">Unix.sockaddr -><br> f:(Pervasives.in_channel -> Pervasives.out_channel -> 'a) -> 'a</code></pre><div class="info ">
Wrap <code class="code"><span class="constructor">Unix</span>.open_connection</code> with a handler<br>
<b>Since</b> 0.16<br>
</div>
<pre><span id="EXCEPTIONExitServer"><span class="keyword">exception</span> ExitServer</span></pre>
<pre><span id="VALestablish_server"><span class="keyword">val</span> establish_server</span> : <code class="type">Unix.sockaddr -><br> f:(Pervasives.in_channel -> Pervasives.out_channel -> 'a) -> unit</code></pre><div class="info ">
Listen on the address and calls the handler in a blocking fashion.
Using <code class="code"><span class="constructor">Thread</span></code> is recommended if handlers might take time.
The callback should raise <a href="CCUnix.html#EXCEPTIONExitServer"><code class="code"><span class="constructor">CCUnix</span>.<span class="constructor">ExitServer</span></code></a> to stop the loop.<br>
<b>Since</b> 0.16<br>
</div>
<br>
<h2 id="2_InfixFunctions">Infix Functions</h2><br>
<pre><span class="keyword">module</span> <a href="CCUnix.Infix.html">Infix</a>: <code class="code"><span class="keyword">sig</span></code> <a href="CCUnix.Infix.html">..</a> <code class="code"><span class="keyword">end</span></code></pre>
<pre><span class="keyword">include</span> <a href="CCUnix.Infix.html">CCUnix.Infix</a></pre>
</body></html>