2019-05-28 19:21:45 +00:00
|
|
|
# `@actions/exec`
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
2019-08-04 13:00:04 +00:00
|
|
|
#### Basic
|
|
|
|
|
|
|
|
You can use this package to execute your tools on the command line in a cross platform way:
|
|
|
|
|
2019-08-21 05:18:00 +00:00
|
|
|
```js
|
2019-08-04 13:00:04 +00:00
|
|
|
const exec = require('@actions/exec');
|
|
|
|
|
|
|
|
await exec.exec('node index.js');
|
|
|
|
```
|
|
|
|
|
|
|
|
#### Args
|
|
|
|
|
|
|
|
You can also pass in arg arrays:
|
|
|
|
|
2019-08-21 05:18:00 +00:00
|
|
|
```js
|
2019-08-04 13:00:04 +00:00
|
|
|
const exec = require('@actions/exec');
|
|
|
|
|
|
|
|
await exec.exec('node', ['index.js', 'foo=bar']);
|
|
|
|
```
|
|
|
|
|
|
|
|
#### Output/options
|
|
|
|
|
|
|
|
Capture output or specify [other options](https://github.com/actions/toolkit/blob/d9347d4ab99fd507c0b9104b2cf79fb44fcc827d/packages/exec/src/interfaces.ts#L5):
|
|
|
|
|
2019-08-21 05:18:00 +00:00
|
|
|
```js
|
2019-08-04 13:00:04 +00:00
|
|
|
const exec = require('@actions/exec');
|
|
|
|
|
2019-08-26 12:41:40 +00:00
|
|
|
let myOutput = '';
|
|
|
|
let myError = '';
|
2019-08-04 13:00:04 +00:00
|
|
|
|
|
|
|
const options = {};
|
|
|
|
options.listeners = {
|
|
|
|
stdout: (data: Buffer) => {
|
|
|
|
myOutput += data.toString();
|
|
|
|
},
|
|
|
|
stderr: (data: Buffer) => {
|
|
|
|
myError += data.toString();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
options.cwd = './lib';
|
|
|
|
|
|
|
|
await exec.exec('node', ['index.js', 'foo=bar'], options);
|
|
|
|
```
|
|
|
|
|
|
|
|
#### Exec tools not in the PATH
|
|
|
|
|
|
|
|
You can use it in conjunction with the `which` function from `@actions/io` to execute tools that are not in the PATH:
|
|
|
|
|
2019-08-21 05:18:00 +00:00
|
|
|
```js
|
2019-08-04 13:00:04 +00:00
|
|
|
const exec = require('@actions/exec');
|
|
|
|
const io = require('@actions/io');
|
|
|
|
|
|
|
|
const pythonPath: string = await io.which('python', true)
|
|
|
|
|
|
|
|
await exec.exec(`"${pythonPath}"`, ['main.py']);
|
|
|
|
```
|