I am working on a VS Code extension where I have written webviews. If someone clicks on the form button, the terminal generates a command using terminal.sendText(command, true)
. However, I need a response from the executed command, so I am using the logic below:
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)
}
but I am getting below error:-
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.
So I tried the above logic and searched multiple places but didn't get any results.
I want it when run the command it give me the response using that response I can go further or if its error shows accordingly.
Resolved by adding {cwd} in below line:
const { stdout, stderr } = await exec(`npx gui-generator ${this._createCommandString(message)}`, { cwd });