我正在开发一个 VS Code 扩展,我在其中编写了 webview。如果有人单击表单按钮,终端会使用
terminal.sendText(command, true)
生成命令。但是,我需要执行命令的响应,因此我使用以下逻辑:
const exec = util.promisify(child_process.exec);
try {
const { stdout, stderr } = await exec(ecCommand)
console.log('testing', stdout, stderr)
vscode.window.showInformationMessage(stdout);
} catch (e: any) {
vscode.window.showErrorMessage(e.stderr);
this.guiGeneratorPanel?.webview.postMessage({ command: 'err' })
console.log(e)
}
但我遇到以下错误:-
Error: Command failed: cd c:\Users\test; npx gui-generator -r api/test -m GET -t "program:test.yaml" -f test
The system cannot find the path specified.
所以我尝试了上面的逻辑,并搜索了多个地方,但没有得到任何结果。
我希望在运行命令时它能使用该响应给我响应,我可以进一步进行操作,或者如果它的错误相应地显示出来。
通过在下面的行中添加 {cwd} 来解决:
const { stdout, stderr } = await exec(`npx gui-generator ${this._createCommandString(message)}`, { cwd });