Add three new example scripts demonstrating the fswatch, sysinfo, and udp modules with file watching, system metrics, and UDP echo server/client patterns. Reorder the manual API sidebar navigation to list modules alphabetically, removing deprecated entries like websocket, tls, net, json, regex, jinja, os, signal, subprocess, sqlite, and timer while adding argparse, dataset, fswatch, and html.
205 lines
9.8 KiB
HTML
205 lines
9.8 KiB
HTML
<!DOCTYPE html>
|
|
<!-- retoor <retoor@molodetz.nl> -->
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>subprocess - Wren-CLI Manual</title>
|
|
<link rel="stylesheet" href="../css/style.css">
|
|
</head>
|
|
<body>
|
|
<button class="mobile-menu-toggle">Menu</button>
|
|
<div class="container">
|
|
<aside class="sidebar">
|
|
<div class="sidebar-header">
|
|
<h1><a href="../index.html">Wren-CLI</a></h1>
|
|
<div class="version">v0.4.0</div>
|
|
</div>
|
|
<nav class="sidebar-nav">
|
|
<div class="section">
|
|
<span class="section-title">Getting Started</span>
|
|
<ul>
|
|
<li><a href="../getting-started/index.html">Overview</a></li>
|
|
<li><a href="../getting-started/installation.html">Installation</a></li>
|
|
<li><a href="../getting-started/first-script.html">First Script</a></li>
|
|
<li><a href="../getting-started/repl.html">Using the REPL</a></li>
|
|
</ul>
|
|
</div>
|
|
<div class="section">
|
|
<span class="section-title">Language</span>
|
|
<ul>
|
|
<li><a href="../language/index.html">Syntax Overview</a></li>
|
|
<li><a href="../language/classes.html">Classes</a></li>
|
|
<li><a href="../language/methods.html">Methods</a></li>
|
|
<li><a href="../language/control-flow.html">Control Flow</a></li>
|
|
<li><a href="../language/fibers.html">Fibers</a></li>
|
|
<li><a href="../language/modules.html">Modules</a></li>
|
|
</ul>
|
|
</div>
|
|
<div class="section">
|
|
<span class="section-title">API Reference</span>
|
|
<ul>
|
|
<li><a href="index.html">Overview</a></li>
|
|
<li><a href="string.html">String</a></li>
|
|
<li><a href="number.html">Num</a></li>
|
|
<li><a href="argparse.html">argparse</a></li>
|
|
<li><a href="base64.html">base64</a></li>
|
|
<li><a href="crypto.html">crypto</a></li>
|
|
<li><a href="dataset.html">dataset</a></li>
|
|
<li><a href="datetime.html">datetime</a></li>
|
|
<li><a href="dns.html">dns</a></li>
|
|
<li><a href="env.html">env</a></li>
|
|
<li><a href="fswatch.html">fswatch</a></li>
|
|
<li><a href="html.html">html</a></li>
|
|
<li><a href="http.html">http</a></li>
|
|
<li><a href="io.html">io</a></li>
|
|
<li><a href="jinja.html">jinja</a></li>
|
|
<li><a href="json.html">json</a></li>
|
|
<li><a href="markdown.html">markdown</a></li>
|
|
<li><a href="math.html">math</a></li>
|
|
<li><a href="net.html">net</a></li>
|
|
<li><a href="os.html">os</a></li>
|
|
<li><a href="pathlib.html">pathlib</a></li>
|
|
<li><a href="regex.html">regex</a></li>
|
|
<li><a href="scheduler.html">scheduler</a></li>
|
|
<li><a href="signal.html">signal</a></li>
|
|
<li><a href="sqlite.html">sqlite</a></li>
|
|
<li><a href="subprocess.html" class="active">subprocess</a></li>
|
|
<li><a href="sysinfo.html">sysinfo</a></li>
|
|
<li><a href="tempfile.html">tempfile</a></li>
|
|
<li><a href="timer.html">timer</a></li>
|
|
<li><a href="tls.html">tls</a></li>
|
|
<li><a href="udp.html">udp</a></li>
|
|
<li><a href="uuid.html">uuid</a></li>
|
|
<li><a href="wdantic.html">wdantic</a></li>
|
|
<li><a href="web.html">web</a></li>
|
|
<li><a href="websocket.html">websocket</a></li>
|
|
</ul>
|
|
</div>
|
|
<div class="section">
|
|
<span class="section-title">Tutorials</span>
|
|
<ul>
|
|
<li><a href="../tutorials/index.html">Tutorial List</a></li>
|
|
<li><a href="../tutorials/http-client.html">HTTP Client</a></li>
|
|
<li><a href="../tutorials/websocket-chat.html">WebSocket Chat</a></li>
|
|
<li><a href="../tutorials/database-app.html">Database App</a></li>
|
|
<li><a href="../tutorials/template-rendering.html">Templates</a></li>
|
|
<li><a href="../tutorials/cli-tool.html">CLI Tool</a></li>
|
|
</ul>
|
|
</div>
|
|
<div class="section">
|
|
<span class="section-title">How-To Guides</span>
|
|
<ul>
|
|
<li><a href="../howto/index.html">How-To List</a></li>
|
|
<li><a href="../howto/http-requests.html">HTTP Requests</a></li>
|
|
<li><a href="../howto/json-parsing.html">JSON Parsing</a></li>
|
|
<li><a href="../howto/regex-patterns.html">Regex Patterns</a></li>
|
|
<li><a href="../howto/file-operations.html">File Operations</a></li>
|
|
<li><a href="../howto/async-operations.html">Async Operations</a></li>
|
|
<li><a href="../howto/error-handling.html">Error Handling</a></li>
|
|
</ul>
|
|
</div>
|
|
</nav>
|
|
</aside>
|
|
<main class="content">
|
|
<nav class="breadcrumb">
|
|
<a href="../index.html">Home</a>
|
|
<span class="separator">/</span>
|
|
<a href="index.html">API Reference</a>
|
|
<span class="separator">/</span>
|
|
<span>subprocess</span>
|
|
</nav>
|
|
|
|
<article>
|
|
<h1>subprocess</h1>
|
|
|
|
<p>The <code>subprocess</code> module allows running external commands and capturing their output.</p>
|
|
|
|
<pre><code>import "subprocess" for Subprocess</code></pre>
|
|
|
|
<h2>Subprocess Class</h2>
|
|
|
|
<div class="class-header">
|
|
<h3>Subprocess</h3>
|
|
<p>External process execution</p>
|
|
</div>
|
|
|
|
<h3>Static Methods</h3>
|
|
|
|
<div class="method-signature">
|
|
<span class="method-name">Subprocess.run</span>(<span class="param">command</span>) → <span class="type">Map</span>
|
|
</div>
|
|
<p>Runs a command and waits for it to complete.</p>
|
|
<ul class="param-list">
|
|
<li><span class="param-name">command</span> <span class="param-type">(List)</span> - Command and arguments as a list</li>
|
|
<li><span class="returns">Returns:</span> Map with "stdout", "stderr", and "exitCode"</li>
|
|
</ul>
|
|
<pre><code>var result = Subprocess.run(["ls", "-la"])
|
|
System.print("Exit code: %(result["exitCode"])")
|
|
System.print("Output: %(result["stdout"])")</code></pre>
|
|
|
|
<div class="method-signature">
|
|
<span class="method-name">Subprocess.run</span>(<span class="param">command</span>, <span class="param">input</span>) → <span class="type">Map</span>
|
|
</div>
|
|
<p>Runs a command with input data provided to stdin.</p>
|
|
<ul class="param-list">
|
|
<li><span class="param-name">command</span> <span class="param-type">(List)</span> - Command and arguments</li>
|
|
<li><span class="param-name">input</span> <span class="param-type">(String)</span> - Input to send to stdin</li>
|
|
</ul>
|
|
<pre><code>var result = Subprocess.run(["cat"], "Hello, World!")
|
|
System.print(result["stdout"]) // Hello, World!</code></pre>
|
|
|
|
<h2>Examples</h2>
|
|
|
|
<h3>Running Commands</h3>
|
|
<pre><code>import "subprocess" for Subprocess
|
|
|
|
var result = Subprocess.run(["echo", "Hello"])
|
|
System.print(result["stdout"]) // Hello
|
|
|
|
var files = Subprocess.run(["ls", "-la", "/tmp"])
|
|
System.print(files["stdout"])</code></pre>
|
|
|
|
<h3>Checking Exit Codes</h3>
|
|
<pre><code>import "subprocess" for Subprocess
|
|
|
|
var result = Subprocess.run(["grep", "pattern", "file.txt"])
|
|
if (result["exitCode"] == 0) {
|
|
System.print("Found: %(result["stdout"])")
|
|
} else {
|
|
System.print("Not found or error")
|
|
}</code></pre>
|
|
|
|
<h3>Processing Data</h3>
|
|
<pre><code>import "subprocess" for Subprocess
|
|
import "json" for Json
|
|
|
|
var result = Subprocess.run(["curl", "-s", "https://api.example.com/data"])
|
|
if (result["exitCode"] == 0) {
|
|
var data = Json.parse(result["stdout"])
|
|
System.print(data)
|
|
}</code></pre>
|
|
|
|
<h3>Piping Data</h3>
|
|
<pre><code>import "subprocess" for Subprocess
|
|
|
|
var input = "line1\nline2\nline3"
|
|
var result = Subprocess.run(["wc", "-l"], input)
|
|
System.print("Lines: %(result["stdout"].trim())")</code></pre>
|
|
|
|
<div class="admonition warning">
|
|
<div class="admonition-title">Warning</div>
|
|
<p>Commands are not executed through a shell. Use explicit command and argument lists, not shell command strings.</p>
|
|
</div>
|
|
</article>
|
|
|
|
<footer class="page-footer">
|
|
<a href="sqlite.html" class="prev">sqlite</a>
|
|
<a href="sysinfo.html" class="next">sysinfo</a>
|
|
</footer>
|
|
</main>
|
|
</div>
|
|
<script src="../js/main.js"></script>
|
|
</body>
|
|
</html>
|