import { Subject } from "rxjs";
import { exec, execSync } from "child_process";

var fs = require('fs');


export class ShellExecutor {
  querying = new Subject<string>();

   runCommand(comm: string, cb?: (result: string) => void): void {
     this.run(comm, cb);
  }

  private  run(com: string, cb?: (result: string) => void): void {
    if (cb) {
      exec(com,  (error, stdout) => {
        if (error) {
          this.querying.next(`error: ${error.message}`);
        }
        if (cb) {
           cb(stdout);
        }
      });
    } else {
      execSync(com);
    }
  }
}
