Interface: Shell
CloudControl Pro 9 Docs / shell / Shell
Interface: Shell
shell.Shell
Shell class. Created new instance by createShell.
Hierarchy
-
unknown↳
Shell
Table of contents
Methods
Events
Methods
exec
▸ exec(cmd): Promise<ExecutionResult>
Execute a shell command and wait for the result asynchronously.
Example
"nodejs";
const { createShell } = require('shell');
async function main() {
const shell = createShell();
console.log(await shell.exec("touch test.txt"));
console.log(await shell.exec("ls -l test.txt"));
await shell.exit();
}
main();
Parameters
| Name | Type | Description |
|---|---|---|
cmd |
string |
Shell command to execute |
Returns
Promise<ExecutionResult>
Promise of the execution result
exit
▸ exit(forcedly?): Promise<ExitResult>
Exit the shell process. If forcedly is true, the process will be terminated and the return value will be a string representing the signal that killed the process. If forcedly is false, the process will be terminated by exit command and the return value will be the exit code.
Parameters
| Name | Type |
|---|---|
forcedly? |
boolean |
Returns
Promise<ExitResult>
submit
▸ submit(input): void
Submit text to shell's standard input. If the text does not end with a newline character, a newline character will be appended automatically.
Parameters
| Name | Type |
|---|---|
input |
string |
Returns
void
Events
on
▸ on(event, listener): Shell
Event emitted when shell's standard output or standard error has new data. type parameter is used to distinguish standard output and standard error.
data
Parameters
| Name | Type |
|---|---|
event |
"data" |
listener |
(chunk: Buffer, type: StandardOutputType) => void |
Returns
▸ on(event, listener): Shell
Event emitted when shell's standard output or standard error has new line. type parameter is used to distinguish standard output and standard error.
line
Parameters
| Name | Type |
|---|---|
event |
"line" |
listener |
(line: string, type: StandardOutputType) => void |
