Skip to content

Commit

Permalink
replace exec with execFile
Browse files Browse the repository at this point in the history
  • Loading branch information
69 committed Mar 31, 2020
1 parent 075a1c7 commit 1d0525a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
8 changes: 3 additions & 5 deletions lib/index.js
Expand Up @@ -5,7 +5,7 @@ const _ = require("lodash");
//import nodeify from '../node_modules/nodeify-ts/lib/';
const nodeify_ts_1 = require("nodeify-ts");
const child_process = require("child_process");
const exec = child_process.exec;
const execFile = child_process.execFile;
const extractResult = (result) => {
try {
result.object = JSON.parse(result.raw);
Expand All @@ -25,9 +25,7 @@ class Aws {
}
command(command, callback) {
let aws = this;
let execCommand = 'aws ' + command;
const promise = Promise.resolve().then(function () {
//console.log('execCommand =', execCommand);
const env_vars = ('HOME PATH AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY ' +
'AWS_SESSION_TOKEN AWS_DEFAULT_REGION ' +
'AWS_DEFAULT_PROFILE AWS_CONFIG_FILE').split(' ');
Expand All @@ -54,7 +52,7 @@ class Aws {
};
//console.log('exec options =', execOptions);
return new Promise((resolve, reject) => {
exec(execCommand, execOptions, (error, stdout, stderr) => {
execFile('aws', [...command.split(' ')], execOptions, (error, stdout, stderr) => {
if (error) {
const message = `error: '${error}' stdout = '${stdout}' stderr = '${stderr}'`;
console.error(message);
Expand All @@ -66,7 +64,7 @@ class Aws {
});
}).then((data) => {
let result = {
command: execCommand,
command,
error: data.stderr,
object: null,
raw: data.stdout,
Expand Down
8 changes: 3 additions & 5 deletions src/index.ts
Expand Up @@ -3,7 +3,7 @@ import * as _ from 'lodash';
//import nodeify from '../node_modules/nodeify-ts/lib/';
import nodeify from 'nodeify-ts';
import * as child_process from 'child_process';
const exec = child_process.exec;
const execFile = child_process.execFile;


const extractResult = (result: Result): Result => {
Expand All @@ -25,10 +25,8 @@ export class Aws {

public command(command: string, callback?: (err: any, data: any) => void) {
let aws = this;
let execCommand = 'aws ' + command;

const promise = Promise.resolve().then(function () {
//console.log('execCommand =', execCommand);


const env_vars = ('HOME PATH AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY ' +
Expand Down Expand Up @@ -66,7 +64,7 @@ export class Aws {
//console.log('exec options =', execOptions);

return new Promise<{ stderr: string, stdout: string }>( (resolve, reject) => {
exec(execCommand, execOptions, (error, stdout, stderr) => {
execFile('aws', [...command.split(' ')], execOptions, (error: Error | null, stdout: string, stderr: string) => {
if (error) {
const message = `error: '${error}' stdout = '${stdout}' stderr = '${stderr}'`;
console.error(message);
Expand All @@ -79,7 +77,7 @@ export class Aws {
}).then((data: { stderr: string, stdout: string }) => {

let result: Result = {
command: execCommand,
command,
error: data.stderr,
object: null,
raw: data.stdout,
Expand Down

0 comments on commit 1d0525a

Please sign in to comment.