GithubHelp home page GithubHelp logo

hugojosefson / deno-run-simple Goto Github PK

View Code? Open in Web Editor NEW
8.0 3.0 1.0 63 KB

Simple run function to execute shell commands in Deno.

Home Page: https://deno.land/x/run_simple

License: MIT License

TypeScript 100.00%
bash command deno exec process run sh shell simple spawn

deno-run-simple's Introduction

run_simple

Simple run function to execute shell commands in Deno.

Returns a Promise of what the command printed.

The promise rejects with status if the command fails.

API

See the documentation, generated from the latest release.

Usage

// example.ts

import { run } from "https://deno.land/x/run_simple/mod.ts";

// 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 },
);
deno run --allow-run ./example.ts

deno-run-simple's People

Contributors

hugojosefson avatar kuppit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

kuppit

deno-run-simple's Issues

Error: [non-error-thrown] [object Object]

Firstly, thanks a lot for simpe-run, it's really epic! 🧡 🧡 🧡

I'm seeing some errors produced like so:

Error: [non-error-thrown] [object Object]

I can't see the contents of the error because I just get [object Object]. From looking at the code it looks like run() throws a non error if the script exits with a non zero code. Is there a way to unpack the error and get it logged? Or would it make sense to extend the error class and throw that?

feat: extractShebangCommand

Add below function:

/**
 * Extracts the command to run a script, from its shebang line.
 * @param scriptContents the script source code
 * @returns array of command and parameters
 */
export function extractShebangCommand(scriptContents: string): string[] {
  return scriptContents.split("\n")[0].replace(/^#!/, "").split(" ");
}

...with the following edits:

TODO

  • Use .split("\n", 1) to not read more than necessary.
  • Use npm:[email protected] instead of .split(" ").
  • Return some more "Command":y type from this repo?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.