lando.shell.sh(cmd, [opts]) ⇒ Promise
Runs a command.
This is an abstraction method that:
- Delegates to either node's native
spawn
orexec
methods. - Promisifies the calling of these function
- Handles
stdout
,stdin
andstderr
See
Since: 3.0.0
Param | Type | Default | Description |
---|---|---|---|
cmd | Array |
The command to run as elements in an array. | |
[opts] | Object |
Options to help determine how the exec is run. | |
[opts.mode] | Boolean |
'exec' |
The mode to run in |
[opts.detached] | Boolean |
false |
Whether we are running in detached mode or not (deprecated) |
[opts.cwd] | Boolean |
process.cwd() |
The directory to run the command from |
Returns: Promise
- A promise with collected results if applicable.
Example
// Run a command in collect mode
return lando.shell.sh(['ls', '-lsa', '/'], {mode: 'collect'})
// Catch and log any errors
.catch(err => {
lando.log.error(err);
})
// Print the collected results of the command
.then(results => {
console.log(results);
});
lando.shell.which(cmd) ⇒ String
\| null
Returns the path of a specific command or binary.
Since: 3.0.0
Param | Type | Description |
---|---|---|
cmd | String |
A command to search for. |
Returns: String
| null
- The path to the command or null.
Example
// Determine the location of the 'docker' command
const which = lando.shell.which(DOCKER_EXECUTABLE);