Skip to content

Commit aa5b939

Browse files
authored
Merge pull request #1988 from denisbredikhin/exec-fix
solve issue with running tool when there are spaces in its path
2 parents 0e6d9d2 + 015244e commit aa5b939

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

src/agents/common/build-agent.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { exec as execNonPromise, ExecOptions } from 'node:child_process'
1+
import { execFile as execFileNonPromise, ExecFileOptions } from 'node:child_process'
22
import * as fs from 'node:fs/promises'
33
import * as process from 'node:process'
44
import * as path from 'node:path'
@@ -251,24 +251,29 @@ export abstract class BuildAgentBase implements IBuildAgent {
251251
}
252252

253253
async exec(cmd: string, args: string[]): Promise<ExecResult> {
254-
const exec = util.promisify(execNonPromise)
254+
const execFile = util.promisify(execFileNonPromise)
255255

256256
try {
257-
const commandOptions: ExecOptions = { maxBuffer: 1024 * 1024 * 10 } // 10MB
258-
const { stdout, stderr } = await exec(`${cmd} ${args.join(' ')}`, commandOptions)
257+
const commandOptions: ExecFileOptions = { maxBuffer: 1024 * 1024 * 10 } // 10MB
258+
const { stdout, stderr } = await execFile(cmd, args, commandOptions)
259+
const normalizedStdout = typeof stdout === 'string' ? stdout : stdout?.toString()
260+
const normalizedStderr = typeof stderr === 'string' ? stderr : stderr?.toString()
259261
return {
260262
code: 0,
261263
error: null,
262-
stderr,
263-
stdout
264+
stderr: normalizedStderr,
265+
stdout: normalizedStdout
264266
}
265267
} catch (e) {
266-
const error = e as Error & { code: number; stderr: string; stdout: string }
268+
const error = e as Error & { code?: number | string; stderr?: string | Buffer; stdout?: string | Buffer }
269+
const normalizedStdout = typeof error.stdout === 'string' ? error.stdout : error.stdout?.toString()
270+
const normalizedStderr = typeof error.stderr === 'string' ? error.stderr : (error.stderr?.toString() ?? error.message)
271+
const exitCode = typeof error.code === 'number' ? error.code : -1
267272
return {
268-
code: error.code,
273+
code: exitCode,
269274
error,
270-
stderr: error.stderr,
271-
stdout: error.stdout
275+
stderr: normalizedStderr,
276+
stdout: normalizedStdout
272277
}
273278
}
274279
}

src/tools/common/dotnet-tool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export abstract class DotnetTool implements IDotnetTool {
196196
toolPath = await this.buildAgent.which(this.toolName, true)
197197
}
198198

199-
args = ['--roll-forward Major', ...args]
199+
args = [`--roll-forward`, `Major`, ...args]
200200
return await this.execute(toolPath, args)
201201
}
202202

0 commit comments

Comments
 (0)