An open API service indexing awesome lists of open source software.

https://github.com/suns-echoes/exec

Exec Utility
https://github.com/suns-echoes/exec

cmd exec nodejs shell

Last synced: 4 months ago
JSON representation

Exec Utility

Awesome Lists containing this project

README

          

Exec Utility
============

**Execute command**

The `exec` function simplifies execution of shell commands.

Note: The stderr and stdout is concatenated into output property. The end of this output is trimmed.

Note: The stderr is concatenated into output error property. The end of error is trimmed.

Installation
------------

`npm i @suns-echoes/exec`

Impport
-------

```js
// Import library distribution file
import { exec } from '@suns-echoes/exec';
```

```js
// Import library from source
import { exec } from '@suns-echoes/exec/src';
// or
import { exec } from '@suns-echoes/exec/src/exec';
```

Usage
-----

```js
const { code, error, output } = await exec(cmd, [...args], { buffer, stderr, stdout });
```

### Arguments

* `` `cmd` - entity path;
* `` `[args]` - optional, entity path;
* `` `[config]` - optional, entity path:
* `` `[buffer=true]` - optional, enable unified output;
* `` `[stderr=null]` - optional, stderr callback;
* `` `[stdout=null]` - optional, stdout callback.

### Returns

* `` - the promise of execution.

### Resolves

* `` - exit information:
* `` `code` - exit code
* `` `error` - error output
* `` `output` - unified output (concatenated stderr and stdout)

Examples
--------

### simple use

```js
// simple command with param
const result = await exec('node -v');
// or with params in array
const result = await exec('node', ['-v']);

// result:
// {
// code: 0,
// error: null,
// output: 'v12.1.1',
// }
```

### real-time output (stderr, stdout)

```js
await exec('some_command', ['possible', 'params'], {
// optionally disable ouptut
buffer: false,
stderr: (data) => { ... },
stdout: (data) => { ... },
});
```

License
-------

Licensed under MIT

Copyright (c) 2019 Aneta Suns