Skip to content

Commit

Permalink
SSH output improvements (#10292)
Browse files Browse the repository at this point in the history
  • Loading branch information
xisui-MSFT authored Jan 5, 2023
1 parent 62fb757 commit 5a486fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
6 changes: 6 additions & 0 deletions Extension/src/SSH/sshCommandRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,12 @@ export function runInteractiveSshTerminalCommand(args: ITerminalCommandArgs): Pr
if (loggingLevel !== 'None') {
handleOutputLogging(dataWrite.data);
}

if (continueWithoutExiting) {
// Skip the interactors after we have continued since I haven't see a use case for now.
return;
}

stdout += dataWrite.data;

if (interactors) {
Expand Down
16 changes: 12 additions & 4 deletions Extension/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -708,14 +708,14 @@ export interface ProcessReturnType {
}

export async function spawnChildProcess(program: string, args: string[] = [], continueOn?: string, cancellationToken?: vscode.CancellationToken): Promise<ProcessReturnType> {
const programOutput: ProcessOutput = await spawnChildProcessImpl(program, args, continueOn, cancellationToken);
const exitCode: number | NodeJS.Signals | undefined = programOutput.exitCode;
// Do not use CppSettings to avoid circular require()
const settings: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("C_Cpp", null);
const loggingLevel: string | undefined = settings.get<string>("loggingLevel");
if (loggingLevel === "Information" || loggingLevel === "Debug") {
getOutputChannelLogger().appendLine(`$ ${program} ${args.join(' ')}\n${programOutput.stderr || programOutput.stdout}\n`);
getOutputChannelLogger().appendLine(`$ ${program} ${args.join(' ')}`);
}
const programOutput: ProcessOutput = await spawnChildProcessImpl(program, args, continueOn, cancellationToken);
const exitCode: number | NodeJS.Signals | undefined = programOutput.exitCode;
if (programOutput.exitCode) {
return { succeeded: false, exitCode, output: programOutput.stderr || programOutput.stdout || localize('process.exited', 'Process exited with code {0}', exitCode) };
} else {
Expand All @@ -738,6 +738,10 @@ interface ProcessOutput {

async function spawnChildProcessImpl(program: string, args: string[], continueOn?: string, cancellationToken?: vscode.CancellationToken): Promise<ProcessOutput> {
return new Promise(async (resolve, reject) => {
// Do not use CppSettings to avoid circular require()
const settings: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("C_Cpp", null);
const loggingLevel: string | undefined = settings.get<string>("loggingLevel");

let proc: child_process.ChildProcess;
if (await isExecutable(program)) {
proc = child_process.spawn(`.${isWindows() ? '\\' : '/'}${path.basename(program)}`, args, { shell: true, cwd: path.dirname(program) });
Expand All @@ -761,7 +765,11 @@ async function spawnChildProcessImpl(program: string, args: string[], continueOn
let stderr: string = '';
if (proc.stdout) {
proc.stdout.on('data', data => {
stdout += data.toString();
const str: string = data.toString();
if (loggingLevel !== "None") {
getOutputChannelLogger().append(str);
}
stdout += str;
if (continueOn) {
const continueOnReg: string = escapeStringForRegex(continueOn);
if (stdout.search(continueOnReg)) {
Expand Down

0 comments on commit 5a486fc

Please sign in to comment.