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
- Host: GitHub
- URL: https://github.com/suns-echoes/exec
- Owner: suns-echoes
- License: mit
- Created: 2019-08-27T19:03:36.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T08:19:11.000Z (over 3 years ago)
- Last Synced: 2025-09-05T10:52:55.086Z (10 months ago)
- Topics: cmd, exec, nodejs, shell
- Language: JavaScript
- Homepage:
- Size: 464 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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