Working with Input
Send data to process stdin.
Choosing Your Approach
Use .run() for process-to-process pipes (most common):
await run("cat", "file.txt").run("grep", "pattern").toStdout();
Use enumerate() for in-memory data:
await enumerate(["line1", "line2"]).run("grep", "1").toStdout();
Use read() for file input:
await read("input.txt").run("grep", "pattern").toStdout();
Use range() for generated sequences:
await range({ to: 100 }).map(n => n.toString()).run("shuf").toStdout();
Piping Between Processes
The most common way to provide input:
import { run } from "jsr:@j50n/proc@0.23.3";
await run("echo", "hello")
.run("tr", "a-z", "A-Z") // Receives "hello" as stdin
.toStdout();
// HELLO
From Enumerable
Pipe any enumerable to a process:
import { enumerate } from "jsr:@j50n/proc@0.23.3";
const data = ["line 1", "line 2", "line 3"];
await enumerate(data)
.run("grep", "2")
.toStdout();
// line 2
From File
import { read } from "jsr:@j50n/proc@0.23.3";
await read("input.txt")
.run("grep", "pattern")
.toStdout();
Real-World Examples
Filter Data
await read("data.txt")
.run("grep", "ERROR")
.run("sort")
.run("uniq")
.toStdout();
Transform and Process
await read("input.txt")
.lines
.map(line => line.toUpperCase())
.run("sort")
.toStdout();
Generate and Process
import { range } from "jsr:@j50n/proc@0.23.3";
await range({ to: 100 })
.map(n => n.toString())
.run("shuf") // Shuffle
.run("head", "-10")
.toStdout();
Next Steps
- Process Pipelines - Chain commands
- Working with Output - Capture results