Reuse spawnCommand util for more robust command execution

This commit is contained in:
Miro Spönemann
2020-01-23 11:37:55 +01:00
parent fb50244a29
commit 0f35821d14
2 changed files with 19 additions and 30 deletions

View File

@@ -24,9 +24,9 @@
* SOFTWARE.
*/
import { spawnSync } from 'child_process';
import { EOL } from 'os';
import { dirname, normalize, basename } from 'path';
import { normalize, basename } from 'path';
import { spawnCommand } from 'arduino-ide-extension/lib/node/exec-util';
export enum SymbolType {
Function,
@@ -133,28 +133,9 @@ export class SymbolTable {
}
private execute(): Promise<string> {
return new Promise((resolve, reject) => {
if (!this.objdump) {
return reject(new Error('Missing parameter: objdump'));
}
try {
const { stdout, stderr } = spawnSync(this.objdump, [
'--syms',
this.program
], {
cwd: dirname(this.objdump),
windowsHide: true
});
const error = stderr.toString('utf8');
if (error) {
return reject(new Error(error));
}
resolve(stdout.toString('utf8'));
} catch (error) {
return reject(new Error(error));
}
});
if (!this.objdump) {
return Promise.reject(new Error('Missing parameter: objdump'));
}
return spawnCommand(this.objdump, ['--syms', this.program]);
}
}