diff --git a/src/spec-common/commonUtils.ts b/src/spec-common/commonUtils.ts index b8c5d3786..9b42484ed 100644 --- a/src/spec-common/commonUtils.ts +++ b/src/spec-common/commonUtils.ts @@ -42,7 +42,7 @@ export interface ExecFunction { export interface PtyExec { onData: Event; - write(data: string): void; + write?(data: string): void; resize(cols: number, rows: number): void; exit: Promise<{ code: number | undefined; signal: number | undefined }>; terminate(): Promise; @@ -198,14 +198,16 @@ export async function runCommand(options: { return new Promise<{ cmdOutput: string }>((resolve, reject) => { let cmdOutput = ''; - if (stdin) { - p.write(stdin); + const subs: Disposable[] = []; + if (p.write) { + if (stdin) { + p.write(stdin); + } + if (onDidInput) { + subs.push(onDidInput(data => p.write!(data))); + } } - const subs = [ - onDidInput && onDidInput(data => p.write(data)), - ]; - p.onData(chunk => { cmdOutput += chunk; if (print === 'continuous') { @@ -403,7 +405,7 @@ export function plainExecAsPtyExec(plain: ExecFunction, allowInheritTTY: boolean } return { onData: onDataEmitter.event, - write: p.stdin ? p.stdin.write.bind(p.stdin) : () => {}, + write: p.stdin ? p.stdin.write.bind(p.stdin) : undefined, resize: () => {}, exit: p.exit.then(({ code, signal }) => ({ code: typeof code === 'number' ? code : undefined, diff --git a/src/spec-common/injectHeadless.ts b/src/spec-common/injectHeadless.ts index e7eb550a8..ac51e3950 100644 --- a/src/spec-common/injectHeadless.ts +++ b/src/spec-common/injectHeadless.ts @@ -578,10 +578,10 @@ export async function runRemoteCommand(params: { output: Log; onDidInput?: Event } } }); - if (params.onDidInput) { - params.onDidInput(data => p.write(data)); - } else if (params.stdin) { - const listener = (data: Buffer): void => p.write(data.toString()); + if (p.write && params.onDidInput) { + params.onDidInput(data => p.write!(data)); + } else if (p.write && params.stdin) { + const listener = (data: Buffer): void => p.write!(data.toString()); const stdin = params.stdin; if (stdin.isTTY) { stdin.setRawMode(true); diff --git a/src/spec-shutdown/dockerUtils.ts b/src/spec-shutdown/dockerUtils.ts index e5155bb62..5cd07d0e1 100644 --- a/src/spec-shutdown/dockerUtils.ts +++ b/src/spec-shutdown/dockerUtils.ts @@ -311,10 +311,10 @@ export async function dockerComposePtyCLI(params: DockerCLIParameters | PartialP }); } -export function dockerExecFunction(params: DockerCLIParameters | PartialExecParameters | DockerResolverParameters, containerName: string, user: string | undefined): ExecFunction { +export function dockerExecFunction(params: DockerCLIParameters | PartialExecParameters | DockerResolverParameters, containerName: string, user: string | undefined, pty = false): ExecFunction { return async function (execParams: ExecParameters): Promise { const { exec, cmd, args, env } = toExecParameters(params); - const { argsPrefix, args: execArgs } = toDockerExecArgs(containerName, user, execParams, false); + const { argsPrefix, args: execArgs } = toDockerExecArgs(containerName, user, execParams, pty); return exec({ cmd, args: (args || []).concat(execArgs), @@ -328,7 +328,7 @@ export function dockerExecFunction(params: DockerCLIParameters | PartialExecPara export async function dockerPtyExecFunction(params: PartialPtyExecParameters | DockerResolverParameters, containerName: string, user: string | undefined, loadNativeModule: (moduleName: string) => Promise, allowInheritTTY: boolean): Promise { const pty = await loadNativeModule('node-pty'); if (!pty) { - const plain = dockerExecFunction(params, containerName, user); + const plain = dockerExecFunction(params, containerName, user, true); return plainExecAsPtyExec(plain, allowInheritTTY); }