https://github.com/hugojosefson/deno-run-simple
Simple `run` function to execute shell commands in Deno.
https://github.com/hugojosefson/deno-run-simple
bash command deno exec process run sh shell simple spawn
Last synced: 11 months ago
JSON representation
Simple `run` function to execute shell commands in Deno.
- Host: GitHub
- URL: https://github.com/hugojosefson/deno-run-simple
- Owner: hugojosefson
- License: mit
- Created: 2022-07-15T11:58:49.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-04-25T12:40:41.000Z (about 1 year ago)
- Last Synced: 2025-06-09T12:14:38.671Z (12 months ago)
- Topics: bash, command, deno, exec, process, run, sh, shell, simple, spawn
- Language: TypeScript
- Homepage: https://jsr.io/@hugojosefson/run-simple
- Size: 92.8 KB
- Stars: 8
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# @hugojosefson/run-simple
Simple `run` function to execute shell commands in Deno.
Returns a Promise of what the command printed. Rejects with status if the
command fails.
[](https://jsr.io/@hugojosefson/run-simple)
[](https://jsr.io/@hugojosefson/run-simple)
[](https://github.com/hugojosefson/deno-run-simple/actions/workflows/release.yaml)
## Requirements
Requires [Deno](https://deno.com/) v1.46.3 or later. Version 2+ is recommended.
## API
Please see docs on
[jsr.io/@hugojosefson/run-simple](https://jsr.io/@hugojosefson/run-simple).
## Installation
```sh
# add as dependency to your project
deno add jsr:@hugojosefson/run-simple
```
## Example usage
```typescript
// example-usage.ts
import { run } from "@hugojosefson/run-simple";
// Simple command
const dir: string = await run("ls -l");
console.log(dir);
// Command with variable argument
const uid = 1000;
const idLine: string = await run(["id", uid]);
console.log(idLine);
// An argument contains spaces
const remoteHost = "10.20.30.40";
const remoteCommand = "ps -ef --forest";
const remoteProcessTree: string = await run(["ssh", remoteHost, remoteCommand]);
console.log(remoteProcessTree);
// Supply STDIN to the command
const contents = `# Remote file
This will be the contents of the remote file.
`;
await run(
["ssh", remoteHost, "bash", "-c", "cat > remote_file.md"],
{ stdin: contents },
);
```
You may run the above example with:
```sh
deno run --allow-run ./example-usage.ts
```
Or directly from here:
```sh
deno run --allow-run --reload jsr:@hugojosefson/run-simple/example-usage
```