import { } from "@effection-contrib/tinyexec"
tinyexec
Effection compatible wrapper around tinyexec package.
To run a process, use the x
function:
import { x } from "@effection-contrib/tinyexec";
import { each, main } from "effection";
await main(function* () {
let proc = yield* x("echo", ["Hello, World"]);
for (let line of yield* each(proc.lines)) {
console.log(line);
yield* each.next();
}
});
// => prints "Hello, World"
The process will be automatically destroyed whenever it passes out of scope. For
example, the following shows the output of the top
command for five seconds
before exiting.
import { x } from "@effection-contrib/tinyexec";
import { each, main, sleep, spawn } from "effection";
await main(function* () {
yield* spawn(function* () {
let proc = yield* x("top");
for (let line of yield* each(proc.lines)) {
console.log(line);
yield* each.next();
}
});
yield* sleep(5000);
});
API Reference
interface TinyProcess extends Operation<Output>
Wraps a tinyexec process. To create one use the x function.
Properties
- lines: Stream<string, void>
A stream of lines coming from both stdin and stdout. The stream will terminate when stdout and stderr are closed which usually corresponds to the process ending.
Methods
- kill(signaloptional: KillSignal): Operation<void>
Send
signal
to this process
function x(cmd: string, , options?: Partial<Options>): Operation<TinyProcess>
Run OS process with cmd
This will create a TinyProcess resource. If it is still running when it passes out of scope, it will be killed.
Parameters
cmd: string
optionsoptional: Partial<Options>