child-spawn
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

child-spawn

Easily execute shell commands and parse stdout.

import {nl, json, split0} from 'child-spawn'

async function main(args: string[]): Promise<number | void> {
    const lines = await nl`echo ${"foo\nbar"}`
    console.log(lines)

    const pkg = await json`jq -c . package.json`
    console.log(pkg)

    const files = await split0`find . -maxdepth 2 -type f -print0`
    console.log(files)
}

main(process.argv.slice(process.argv.findIndex(f => f === __filename) + 1))
    .then(exitCode => {
        if(typeof exitCode === 'number') {
            process.exitCode = exitCode
        }
    }, err => {
        if(err != null) {
            console.error(err)
        }
        process.exitCode = 255
    })

Readme

Keywords

none

Package Sidebar

Install

npm i child-spawn

Weekly Downloads

1

Version

0.1.2

License

none

Unpacked Size

17.1 kB

Total Files

11

Last publish

Collaborators

  • mnpenner