Skip to content

Commit 1032709

Browse files
author
Kartik Raj
authored
Log commands when using raw process APIs directly (microsoft#22326)
1 parent c3afea5 commit 1032709

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

src/client/common/process/proc.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,24 @@ export class ProcessService extends EventEmitter implements IProcessService {
4040
}
4141

4242
public execObservable(file: string, args: string[], options: SpawnOptions = {}): ObservableExecutionResult<string> {
43-
const result = execObservable(file, args, options, this.env, this.processesToKill);
43+
const execOptions = { ...options, doNotLog: true };
44+
const result = execObservable(file, args, execOptions, this.env, this.processesToKill);
4445
this.emit('exec', file, args, options);
4546
return result;
4647
}
4748

4849
public exec(file: string, args: string[], options: SpawnOptions = {}): Promise<ExecutionResult<string>> {
49-
const promise = plainExec(file, args, options, this.env, this.processesToKill);
50+
const execOptions = { ...options, doNotLog: true };
51+
const promise = plainExec(file, args, execOptions, this.env, this.processesToKill);
5052
this.emit('exec', file, args, options);
5153
return promise;
5254
}
5355

5456
public shellExec(command: string, options: ShellOptions = {}): Promise<ExecutionResult<string>> {
5557
this.emit('exec', command, undefined, options);
5658
const disposables = new Set<IDisposable>();
57-
return shellExec(command, options, this.env, disposables).finally(() => {
59+
const shellOptions = { ...options, doNotLog: true };
60+
return shellExec(command, shellOptions, this.env, disposables).finally(() => {
5861
// Ensure the process we started is cleaned up.
5962
disposables.forEach((p) => {
6063
try {

src/client/common/process/rawProcessApis.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { ExecutionResult, ObservableExecutionResult, Output, ShellOptions, Spawn
1212
import { noop } from '../utils/misc';
1313
import { decodeBuffer } from './decoder';
1414
import { traceVerbose } from '../../logging';
15+
import { WorkspaceService } from '../application/workspace';
16+
import { ProcessLogger } from './logger';
1517

1618
const PS_ERROR_SCREEN_BOGUS = /your [0-9]+x[0-9]+ screen size is bogus\. expect trouble/;
1719

@@ -49,12 +51,16 @@ function getDefaultOptions<T extends ShellOptions | SpawnOptions>(options: T, de
4951

5052
export function shellExec(
5153
command: string,
52-
options: ShellOptions = {},
54+
options: ShellOptions & { doNotLog?: boolean } = {},
5355
defaultEnv?: EnvironmentVariables,
5456
disposables?: Set<IDisposable>,
5557
): Promise<ExecutionResult<string>> {
5658
const shellOptions = getDefaultOptions(options, defaultEnv);
5759
traceVerbose(`Shell Exec: ${command} with options: ${JSON.stringify(shellOptions, null, 4)}`);
60+
if (!options.doNotLog) {
61+
const processLogger = new ProcessLogger(new WorkspaceService());
62+
processLogger.logProcess(command, undefined, shellOptions);
63+
}
5864
return new Promise((resolve, reject) => {
5965
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6066
const callback = (e: any, stdout: any, stderr: any) => {
@@ -90,12 +96,16 @@ export function shellExec(
9096
export function plainExec(
9197
file: string,
9298
args: string[],
93-
options: SpawnOptions = {},
99+
options: SpawnOptions & { doNotLog?: boolean } = {},
94100
defaultEnv?: EnvironmentVariables,
95101
disposables?: Set<IDisposable>,
96102
): Promise<ExecutionResult<string>> {
97103
const spawnOptions = getDefaultOptions(options, defaultEnv);
98104
const encoding = spawnOptions.encoding ? spawnOptions.encoding : 'utf8';
105+
if (!options.doNotLog) {
106+
const processLogger = new ProcessLogger(new WorkspaceService());
107+
processLogger.logProcess(file, args, options);
108+
}
99109
const proc = spawn(file, args, spawnOptions);
100110
// Listen to these errors (unhandled errors in streams tears down the process).
101111
// Errors will be bubbled up to the `error` event in `proc`, hence no need to log.
@@ -192,12 +202,16 @@ function removeCondaRunMarkers(out: string) {
192202
export function execObservable(
193203
file: string,
194204
args: string[],
195-
options: SpawnOptions = {},
205+
options: SpawnOptions & { doNotLog?: boolean } = {},
196206
defaultEnv?: EnvironmentVariables,
197207
disposables?: Set<IDisposable>,
198208
): ObservableExecutionResult<string> {
199209
const spawnOptions = getDefaultOptions(options, defaultEnv);
200210
const encoding = spawnOptions.encoding ? spawnOptions.encoding : 'utf8';
211+
if (!options.doNotLog) {
212+
const processLogger = new ProcessLogger(new WorkspaceService());
213+
processLogger.logProcess(file, args, options);
214+
}
201215
const proc = spawn(file, args, spawnOptions);
202216
let procExited = false;
203217
const disposable: IDisposable = {

0 commit comments

Comments
 (0)