filmout_manager can launch the fd binary and connect to its socket server, now. Add dotenv features to load settings from a file.
This commit is contained in:
parent
5746672a86
commit
2728986258
|
@ -1,2 +1,3 @@
|
|||
node_modules
|
||||
*.DS_Store
|
||||
.env
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
HOST=0.0.0.0
|
||||
PORT=8081
|
||||
WS_HOST=0.0.0.0
|
||||
WS_PORT=8081
|
||||
WIDTH=2560
|
||||
HEIGHT=1600
|
||||
FD=../filmout_display/build/bin/fd
|
||||
FD_HOST=localhost
|
||||
FD_PORT=8081
|
|
@ -0,0 +1,79 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.FD = void 0;
|
||||
const net_1 = __importDefault(require("net"));
|
||||
const log_1 = require("../log");
|
||||
const shell_1 = require("../shell");
|
||||
const delay_1 = require("../delay");
|
||||
class FD {
|
||||
constructor(bin, width, height, host, port) {
|
||||
this.socketAvailable = false;
|
||||
this.socketConnected = false;
|
||||
this.bin = bin;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
this.log = (0, log_1.createLog)('fd');
|
||||
this.shell = new shell_1.Shell([this.bin, `${this.width}`, `${this.height}`], this.logstd.bind(this), this.logsterr.bind(this), null, true);
|
||||
this.startDisplay();
|
||||
this.startClient();
|
||||
this.test();
|
||||
}
|
||||
async startDisplay() {
|
||||
this.log.info(`Launching fd binary ${this.bin}`);
|
||||
this.shell.execute();
|
||||
}
|
||||
async startClient() {
|
||||
this.client = new net_1.default.Socket();
|
||||
this.log.info(`Waiting for TCP socket server on ${this.host}:${this.port}...`);
|
||||
while (!this.socketAvailable) {
|
||||
await (0, delay_1.delay)(10);
|
||||
}
|
||||
this.log.info(`TCP socket server on ${this.host}:${this.port} is available`);
|
||||
this.client.connect(this.port, this.host, async function () {
|
||||
this.socketConnected = true;
|
||||
this.log.info(`TCP socket client connected to ${this.host}:${this.port}`);
|
||||
/*const data = {
|
||||
action : 1,
|
||||
image: 'filename.tif',
|
||||
};
|
||||
this.log.info('SENDING');
|
||||
this.log.info(data);
|
||||
this.client.write(JSON.stringify(data));
|
||||
await delay(2000);
|
||||
data.action = 2;
|
||||
this.log.info('SENDING');
|
||||
this.log.info(data);
|
||||
this.client.write(JSON.stringify(data));*/
|
||||
}.bind(this));
|
||||
this.client.on('data', (data) => {
|
||||
this.log.info('RECEIVED');
|
||||
this.log.info(data.toString());
|
||||
});
|
||||
this.client.on('close', () => {
|
||||
this.log.info('Closing connection');
|
||||
});
|
||||
this.client.on('error', (err) => {
|
||||
this.log.error('Error:', err);
|
||||
});
|
||||
}
|
||||
logstd(data) {
|
||||
this.log.info(data);
|
||||
if (data.indexOf('TCP server listening on port') !== -1 && data.indexOf(`${this.port}`) !== -1) {
|
||||
this.socketAvailable = true;
|
||||
}
|
||||
}
|
||||
logsterr(data) {
|
||||
this.log.error(data);
|
||||
}
|
||||
async test() {
|
||||
await (0, delay_1.delay)(10000);
|
||||
this.shell.kill();
|
||||
}
|
||||
}
|
||||
exports.FD = FD;
|
||||
//# sourceMappingURL=index.js.map
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/fd/index.ts"],"names":[],"mappings":";;;;;;AACA,8CAAsB;AAEtB,gCAAkC;AAClC,oCAAiC;AACjC,oCAAiC;AAEjC,MAAa,EAAE;IAYd,YAAa,GAAW,EAAE,KAAc,EAAE,MAAe,EAAE,IAAa,EAAE,IAAa;QAH/E,oBAAe,GAAa,KAAK,CAAC;QAClC,oBAAe,GAAa,KAAK,CAAC;QAGzC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAA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K,CAAC,IAAI;QACjB,MAAM,IAAA,aAAK,EAAC,KAAK,CAAC,CAAC;QACnB,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IACnB,CAAC;CACD;AAnFD,gBAmFC"}
|
|
@ -2,23 +2,50 @@
|
|||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
require("dotenv/config");
|
||||
const log_1 = require("./log");
|
||||
const shell_1 = require("./shell");
|
||||
const delay_1 = require("./delay");
|
||||
const fd_1 = require("./fd");
|
||||
let fd;
|
||||
let log = (0, log_1.createLog)('fm');
|
||||
let logfd = (0, log_1.createLog)('fd');
|
||||
log.info('Starting filmout_manager');
|
||||
function logfdstd(data) {
|
||||
logfd.info(data);
|
||||
}
|
||||
function logfdstderr(data) {
|
||||
logfd.error(data);
|
||||
function settings() {
|
||||
if (typeof process.env['FD'] === 'undefined') {
|
||||
log.error('Please include an FD value containing the path to your fd binary in .env');
|
||||
process.exit(1);
|
||||
}
|
||||
else {
|
||||
log.info(`FD=${process.env['FD']}`);
|
||||
}
|
||||
if (typeof process.env['WIDTH'] === 'undefined') {
|
||||
log.error('Please include a WIDTH value containing the width of the screen you are using in .env');
|
||||
process.exit(2);
|
||||
}
|
||||
else {
|
||||
log.info(`WIDTH=${process.env['WIDTH']}`);
|
||||
}
|
||||
if (typeof process.env['HEIGHT'] === 'undefined') {
|
||||
log.error('Please include a HEIGHT value containing the height of the screen you are using in .env');
|
||||
process.exit(3);
|
||||
}
|
||||
else {
|
||||
log.info(`HEIGHT=${process.env['HEIGHT']}`);
|
||||
}
|
||||
if (typeof process.env['FD_HOST'] === 'undefined') {
|
||||
log.error('Please include a FD_HOST value with the host that the fd socket server is hosted on in .env');
|
||||
process.exit(4);
|
||||
}
|
||||
else {
|
||||
log.info(`FD_HOST=${process.env['FD_HOST']}`);
|
||||
}
|
||||
if (typeof process.env['FD_PORT'] === 'undefined') {
|
||||
log.error('Please include a FD_PORT value with the port that the fd socket server is hosted in in .env');
|
||||
process.exit(5);
|
||||
}
|
||||
else {
|
||||
log.info(`FD_PORT=${process.env['FD_PORT']}`);
|
||||
}
|
||||
}
|
||||
async function main() {
|
||||
let shell = new shell_1.Shell(['../filmout_display/build/bin/fd', '2560', '1600'], logfdstd, logfdstderr, null, true);
|
||||
shell.execute();
|
||||
await (0, delay_1.delay)(5000);
|
||||
shell.kill();
|
||||
process.exit();
|
||||
settings();
|
||||
fd = new fd_1.FD(process.env['FD'], parseInt(process.env['WIDTH']), parseInt(process.env['HEIGHT']), process.env['FD_HOST'], parseInt(process.env['FD_PORT']));
|
||||
}
|
||||
main();
|
||||
//# sourceMappingURL=index.js.map
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,yBAAsB;AAgBtB,+BAAiC;AAEjC,mCAAgC;AAChC,mCAAgC;AAEhC,IAAI,GAAG,GAAY,IAAA,eAAS,EAAC,IAAI,CAAC,CAAC;AACnC,IAAI,KAAK,GAAY,IAAA,eAAS,EAAC,IAAI,CAAC,CAAC;AAErC,GAAG,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;AAErC,SAAS,QAAQ,CAAE,IAAU;IAC5B,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAClB,CAAC;AACD,SAAS,WAAW,CAAE,IAAU;IAC/B,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACnB,CAAC;AAED,KAAK,UAAU,IAAI;IAClB,IAAI,KAAK,GAAW,IAAI,aAAK,CAAC,CAAE,iCAAiC,EAAE,MAAM,EAAE,MAAM,CAAE,EAAE,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IACxH,KAAK,CAAC,OAAO,EAAE,CAAC;IAChB,MAAM,IAAA,aAAK,EAAC,IAAI,CAAC,CAAC;IAClB,KAAK,CAAC,IAAI,EAAE,CAAC;IACb,OAAO,CAAC,IAAI,EAAE,CAAC;AAChB,CAAC;AAED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G,CAAC,SAAS,CAAC,KAAK,WAAW,EAAE,CAAC;QACnD,GAAG,CAAC,KAAK,CAAC,6FAA6F,CAAC,CAAC;QACzG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC;SAAM,CAAC;QACP,GAAG,CAAC,IAAI,CAAC,WAAW,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IAC/C,CAAC;IACD,IAAI,OAAO,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,KAAK,WAAW,EAAE,CAAC;QACnD,GAAG,CAAC,KAAK,CAAC,6FAA6F,CAAC,CAAA;QACxG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC;SAAM,CAAC;QACP,GAAG,CAAC,IAAI,CAAC,WAAW,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IAC/C,CAAC;AACF,CAAC;AAED,KAAK,UAAU,IAAI;IAClB,QAAQ,EAAE,CAAC;IACX,EAAE,GAAG,IAAI,OAAE,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,EAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAG,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,EAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AAC9J,CAAC;AAED,IAAI,EAAE,CAAC"}
|
|
@ -18,11 +18,13 @@ class Shell {
|
|||
this.stderr = stderr;
|
||||
this.silent = silent;
|
||||
this.after = after;
|
||||
if (!this.silent)
|
||||
this.log = (0, log_1.createLog)(bin);
|
||||
}
|
||||
async execute() {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.child = (0, child_process_1.spawn)(this.bin, this.args);
|
||||
if (!this.silent)
|
||||
this.log.info(`Shell: ${this.bin} ${this.args.join(' ')}`);
|
||||
this.child.stdout.on('data', (data) => {
|
||||
if (!this.silent)
|
||||
|
@ -30,7 +32,10 @@ class Shell {
|
|||
if (this.after !== null)
|
||||
this.lines.push(data);
|
||||
if (this.stdio !== null) {
|
||||
this.stdio(data.toString());
|
||||
let lines = data.toString().split(os_1.EOL).filter(el => el.trim() !== '');
|
||||
for (let line of lines) {
|
||||
this.stdio(line);
|
||||
}
|
||||
}
|
||||
});
|
||||
this.child.stderr.on('data', (data) => {
|
||||
|
@ -45,10 +50,12 @@ class Shell {
|
|||
this.after(this.lines.join(os_1.EOL));
|
||||
}
|
||||
if (code === 0) {
|
||||
if (!this.silent)
|
||||
this.log.info(`Complete: ${this.bin} ${this.args.join(' ')}`);
|
||||
return resolve(code);
|
||||
}
|
||||
else {
|
||||
if (!this.silent)
|
||||
this.log.error(`Error executing: ${this.bin} ${this.args.join(' ')}`);
|
||||
return reject(code);
|
||||
}
|
||||
|
@ -56,6 +63,7 @@ class Shell {
|
|||
});
|
||||
}
|
||||
kill() {
|
||||
if (!this.silent)
|
||||
this.log.warn(`Killing: ${this.bin} ${this.args.join(' ')}`);
|
||||
//this.child.stdin.pause();
|
||||
this.child.kill();
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/shell/index.ts"],"names":[],"mappings":";;;AAAA,iDAAsE;AACtE,gCAAmC;AAEnC,2BAAyB;AAEzB,MAAa,KAAK;IAWjB,YAAa,IAAY,EAAE,QAAmB,IAAI,EAAE,SAAoB,IAAI,EAAE,QAAmB,IAAI,EAAE,SAAmB,KAAK;QANvH,UAAK,GAAc,EAAE,CAAC;QACtB,UAAK,GAAc,IAAI,CAAC;QACxB,WAAM,GAAc,IAAI,CAAC;QACzB,UAAK,GAAc,IAAI,CAAC;QACxB,WAAM,GAAa,KAAK,CAAC;QAGhC,MAAM,GAAG,GAAY,IAAI,CAAC,KAAK,EAAE,CAAC;QAClC,IAAI,CAAC,G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,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAG,CAAC,CAAC,CAAC;gBAClC,CAAC;gBACD,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;oBAChB,IAAI,CAAC,IAAI,CAAC,MAAM;wBAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,aAAa,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;oBAChF,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;gBACtB,CAAC;qBAAM,CAAC;oBACP,IAAI,CAAC,IAAI,CAAC,MAAM;wBAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,oBAAoB,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;oBACxF,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;gBACrB,CAAC;YACF,CAAC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;IACJ,CAAC;IAEM,IAAI;QACV,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC/E,2BAA2B;QAC3B,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IACnB,CAAC;CACD;AAlED,sBAkEC;AAED,MAAM,CAAC,OAAO,GAAG,EAAE,KAAK,EAAE,CAAC"}
|
|
@ -0,0 +1,92 @@
|
|||
import type { Logger } from 'winston';
|
||||
import net from 'net';
|
||||
import type { Socket } from 'net';
|
||||
import { createLog } from '../log'
|
||||
import { Shell } from '../shell';
|
||||
import { delay } from '../delay';
|
||||
|
||||
export class FD {
|
||||
private bin : string;
|
||||
private width : number;
|
||||
private height : number;
|
||||
private host : string;
|
||||
private port : number;
|
||||
private shell : Shell;
|
||||
private log : Logger;
|
||||
private client : Socket;
|
||||
private socketAvailable : boolean = false;
|
||||
private socketConnected : boolean = false;
|
||||
|
||||
constructor (bin: string, width : number, height : number, host : string, port : number) {
|
||||
this.bin = bin;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
this.log = createLog('fd');
|
||||
this.shell = new Shell([ this.bin, `${this.width}`, `${this.height}` ], this.logstd.bind(this), this.logsterr.bind(this), null, true);
|
||||
this.startDisplay();
|
||||
this.startClient();
|
||||
this.test();
|
||||
}
|
||||
|
||||
private async startDisplay () {
|
||||
this.log.info(`Launching fd binary ${this.bin}`);
|
||||
this.shell.execute();
|
||||
}
|
||||
|
||||
private async startClient () {
|
||||
this.client = new net.Socket();
|
||||
this.log.info(`Waiting for TCP socket server on ${this.host}:${this.port}...`);
|
||||
while (!this.socketAvailable) {
|
||||
await delay(10);
|
||||
}
|
||||
this.log.info(`TCP socket server on ${this.host}:${this.port} is available`);
|
||||
this.client.connect(this.port, this.host, async function () {
|
||||
this.socketConnected = true;
|
||||
this.log.info(`TCP socket client connected to ${this.host}:${this.port}`);
|
||||
/*const data = {
|
||||
action : 1,
|
||||
image: 'filename.tif',
|
||||
};
|
||||
this.log.info('SENDING');
|
||||
this.log.info(data);
|
||||
this.client.write(JSON.stringify(data));
|
||||
await delay(2000);
|
||||
data.action = 2;
|
||||
this.log.info('SENDING');
|
||||
this.log.info(data);
|
||||
this.client.write(JSON.stringify(data));*/
|
||||
}.bind(this));
|
||||
|
||||
this.client.on('data', (data : string) => {
|
||||
this.log.info('RECEIVED');
|
||||
this.log.info(data.toString());
|
||||
});
|
||||
|
||||
this.client.on('close', () => {
|
||||
this.log.info('Closing connection');
|
||||
});
|
||||
|
||||
this.client.on('error', (err : Error) => {
|
||||
this.log.error('Error:', err);
|
||||
});
|
||||
}
|
||||
|
||||
private logstd ( data : string ) {
|
||||
this.log.info(data);
|
||||
if (data.indexOf('TCP server listening on port') !== -1 && data.indexOf(`${this.port}`) !== -1) {
|
||||
this.socketAvailable = true;
|
||||
}
|
||||
}
|
||||
|
||||
private logsterr ( data : string) {
|
||||
this.log.error(data);
|
||||
}
|
||||
|
||||
private async test () {
|
||||
await delay(10000);
|
||||
this.shell.kill();
|
||||
}
|
||||
}
|
||||
|
50
src/index.ts
50
src/index.ts
|
@ -18,25 +18,51 @@ import { createLog } from './log'
|
|||
import { sendMail } from './mail';
|
||||
import { Shell } from './shell';
|
||||
import { delay } from './delay';
|
||||
import { FD } from './fd';
|
||||
|
||||
|
||||
let fd : FD;
|
||||
|
||||
let log : Logger = createLog('fm');
|
||||
let logfd : Logger = createLog('fd');
|
||||
|
||||
log.info('Starting filmout_manager');
|
||||
|
||||
function logfdstd (data : any) {
|
||||
logfd.info(data);
|
||||
}
|
||||
function logfdstderr (data : any) {
|
||||
logfd.error(data);
|
||||
function settings () {
|
||||
if (typeof process.env['FD'] === 'undefined') {
|
||||
log.error('Please include an FD value containing the path to your fd binary in .env');
|
||||
process.exit(1);
|
||||
} else {
|
||||
log.info(`FD=${process.env['FD']}`);
|
||||
}
|
||||
if (typeof process.env['WIDTH'] === 'undefined') {
|
||||
log.error('Please include a WIDTH value containing the width of the screen you are using in .env');
|
||||
process.exit(2);
|
||||
} else {
|
||||
log.info(`WIDTH=${process.env['WIDTH']}`);
|
||||
}
|
||||
if (typeof process.env['HEIGHT'] === 'undefined') {
|
||||
log.error('Please include a HEIGHT value containing the height of the screen you are using in .env');
|
||||
process.exit(3);
|
||||
} else {
|
||||
log.info(`HEIGHT=${process.env['HEIGHT']}`);
|
||||
}
|
||||
if (typeof process.env['FD_HOST'] === 'undefined') {
|
||||
log.error('Please include a FD_HOST value with the host that the fd socket server is hosted on in .env');
|
||||
process.exit(4);
|
||||
} else {
|
||||
log.info(`FD_HOST=${process.env['FD_HOST']}`);
|
||||
}
|
||||
if (typeof process.env['FD_PORT'] === 'undefined') {
|
||||
log.error('Please include a FD_PORT value with the port that the fd socket server is hosted in in .env')
|
||||
process.exit(5);
|
||||
} else {
|
||||
log.info(`FD_PORT=${process.env['FD_PORT']}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function main () {
|
||||
let shell : Shell = new Shell([ '../filmout_display/build/bin/fd', '2560', '1600' ], logfdstd, logfdstderr, null, true);
|
||||
shell.execute();
|
||||
await delay(5000);
|
||||
shell.kill();
|
||||
process.exit();
|
||||
settings();
|
||||
fd = new FD(process.env['FD'], parseInt(process.env['WIDTH']), parseInt(process.env['HEIGHT']), process.env['FD_HOST'], parseInt(process.env['FD_PORT']));
|
||||
}
|
||||
|
||||
main()
|
||||
main();
|
|
@ -22,20 +22,23 @@ export class Shell {
|
|||
this.stderr = stderr;
|
||||
this.silent = silent;
|
||||
this.after = after;
|
||||
this.log = createLog(bin);
|
||||
if (!this.silent) this.log = createLog(bin);
|
||||
}
|
||||
|
||||
public async execute () : Promise<number> {
|
||||
return new Promise((resolve : Function, reject : Function) => {
|
||||
this.child = spawn(this.bin, this.args);
|
||||
|
||||
this.log.info(`Shell: ${this.bin} ${this.args.join(' ')}`);
|
||||
if (!this.silent) this.log.info(`Shell: ${this.bin} ${this.args.join(' ')}`);
|
||||
|
||||
this.child.stdout.on('data', (data : string) => {
|
||||
if (!this.silent) this.log.info(data.toString());
|
||||
if (this.after !== null) this.lines.push(data);
|
||||
if (this.stdio !== null) {
|
||||
this.stdio(data.toString());
|
||||
let lines : string[] = data.toString().split(EOL).filter( el => el.trim() !== '');
|
||||
for (let line of lines) {
|
||||
this.stdio(line);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -51,10 +54,10 @@ export class Shell {
|
|||
this.after(this.lines.join(EOL));
|
||||
}
|
||||
if (code === 0) {
|
||||
this.log.info(`Complete: ${this.bin} ${this.args.join(' ')}`);
|
||||
if (!this.silent) this.log.info(`Complete: ${this.bin} ${this.args.join(' ')}`);
|
||||
return resolve(code);
|
||||
} else {
|
||||
this.log.error(`Error executing: ${this.bin} ${this.args.join(' ')}`);
|
||||
if (!this.silent) this.log.error(`Error executing: ${this.bin} ${this.args.join(' ')}`);
|
||||
return reject(code);
|
||||
}
|
||||
});
|
||||
|
@ -62,7 +65,7 @@ export class Shell {
|
|||
}
|
||||
|
||||
public kill () {
|
||||
this.log.warn(`Killing: ${this.bin} ${this.args.join(' ')}`);
|
||||
if (!this.silent) this.log.warn(`Killing: ${this.bin} ${this.args.join(' ')}`);
|
||||
//this.child.stdin.pause();
|
||||
this.child.kill();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue