|
|
|
@ -30,44 +30,45 @@ export class Smartshell {
|
|
|
|
|
* executes a given command async
|
|
|
|
|
*/
|
|
|
|
|
private async _exec(options: {
|
|
|
|
|
commandString: string,
|
|
|
|
|
silent?: boolean,
|
|
|
|
|
strict?: boolean,
|
|
|
|
|
streaming?: boolean,
|
|
|
|
|
interactive?: boolean
|
|
|
|
|
commandString: string;
|
|
|
|
|
silent?: boolean;
|
|
|
|
|
strict?: boolean;
|
|
|
|
|
streaming?: boolean;
|
|
|
|
|
interactive?: boolean;
|
|
|
|
|
}): Promise<IExecResult | IExecResultStreaming | void> {
|
|
|
|
|
|
|
|
|
|
if (options.interactive) {
|
|
|
|
|
if (process.env.CI) {
|
|
|
|
|
return;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const done = plugins.smartpromise.defer();
|
|
|
|
|
const shell = cp.spawn('sh', [], { stdio: ['pipe', 'inherit', 'inherit'] });
|
|
|
|
|
this.smartexit.addProcess(shell);
|
|
|
|
|
|
|
|
|
|
shell.on('close', (code) => {
|
|
|
|
|
console.log(`interactive shell terminated with code ${code}`);
|
|
|
|
|
this.smartexit.removeProcess(shell);
|
|
|
|
|
done.resolve();
|
|
|
|
|
|
|
|
|
|
// Notice that stdio is set to 'inherit'
|
|
|
|
|
const shell = cp.spawn(options.commandString, {
|
|
|
|
|
stdio: 'inherit',
|
|
|
|
|
shell: true,
|
|
|
|
|
detached: true
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let commandString = options.commandString;
|
|
|
|
|
|
|
|
|
|
shell.stdin.write(commandString + '\n exit \n');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.smartexit.addProcess(shell);
|
|
|
|
|
|
|
|
|
|
shell.on('close', (code) => {
|
|
|
|
|
console.log(`interactive shell terminated with code ${code}`);
|
|
|
|
|
this.smartexit.removeProcess(shell);
|
|
|
|
|
done.resolve();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await done.promise;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const done = plugins.smartpromise.defer<IExecResult | IExecResultStreaming>();
|
|
|
|
|
const childProcessEnded = plugins.smartpromise.defer<IExecResult>();
|
|
|
|
|
|
|
|
|
|
let commandToExecute = options.commandString;
|
|
|
|
|
commandToExecute = this.shellEnv.createEnvExecString(options.commandString);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const spawnlogInstance = new ShellLog();
|
|
|
|
|
const execChildProcess = cp.spawn(commandToExecute, [], {
|
|
|
|
|
shell: true,
|
|
|
|
@ -143,19 +144,30 @@ export class Smartshell {
|
|
|
|
|
return (await this._exec({ commandString, silent: true, strict: true })) as IExecResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async execStreaming(commandString: string, silent: boolean = false): Promise<IExecResultStreaming> {
|
|
|
|
|
public async execStreaming(
|
|
|
|
|
commandString: string,
|
|
|
|
|
silent: boolean = false
|
|
|
|
|
): Promise<IExecResultStreaming> {
|
|
|
|
|
return (await this._exec({ commandString, silent, streaming: true })) as IExecResultStreaming;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async execStreamingSilent(commandString: string): Promise<IExecResultStreaming> {
|
|
|
|
|
return (await this._exec({ commandString, silent: true, streaming: true })) as IExecResultStreaming;
|
|
|
|
|
return (await this._exec({
|
|
|
|
|
commandString,
|
|
|
|
|
silent: true,
|
|
|
|
|
streaming: true,
|
|
|
|
|
})) as IExecResultStreaming;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async execInteractive(commandString: string) {
|
|
|
|
|
await this._exec({ commandString, interactive: true });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async execAndWaitForLine(commandString: string, regexArg: RegExp, silentArg: boolean = false) {
|
|
|
|
|
public async execAndWaitForLine(
|
|
|
|
|
commandString: string,
|
|
|
|
|
regexArg: RegExp,
|
|
|
|
|
silentArg: boolean = false
|
|
|
|
|
) {
|
|
|
|
|
let done = plugins.smartpromise.defer();
|
|
|
|
|
let execStreamingResult = await this.execStreaming(commandString, silentArg);
|
|
|
|
|
execStreamingResult.childProcess.stdout.on('data', (stdOutChunk: string) => {
|
|
|
|
|