Skip to content

Commit

Permalink
Fix: Callbacks for process.stdout / .stderr (#2810)
Browse files Browse the repository at this point in the history
* Fix callbacks for process.stdout /.stderr

The overrides for `process.stdout.write` and `process.stderr.write` did not invoke the provided callbacks when they’re done.

* Fix: write callback is an optional parameter

* Append encoding parameter to all  calls
  • Loading branch information
rluba authored and vmarchaud committed May 20, 2017
1 parent aeb6137 commit 1b0a89d
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions lib/ProcessContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,15 @@ function exec(script, stds) {
else
log_data = string.toString();

stds.std && stds.std.write && stds.std.write(log_data);
stds.std && stds.std.write && stds.std.write(log_data, encoding);

// hardcoded values of special log path to not write on disk
if (pm2_env.pm_err_log_path !== 'NULL' && pm2_env.pm_err_log_path !== '/dev/null') {
stds.err.write && stds.err.write(log_data, encoding, cb);
};
if (pm2_env.pm_err_log_path !== 'NULL' && pm2_env.pm_err_log_path !== '/dev/null' && stds.err.write) {
stds.err.write(log_data, encoding, cb);
}
else if (cb) {
cb();
}

process.send({
type : 'log:err',
Expand Down Expand Up @@ -235,11 +238,14 @@ function exec(script, stds) {
else
log_data = string.toString();

stds.std && stds.std.write && stds.std.write(log_data);
stds.std && stds.std.write && stds.std.write(log_data, encoding);

// hardcoded values of special log path to not write on disk
if (pm2_env.pm_out_log_path !== 'NULL' && pm2_env.pm_out_log_path !== '/dev/null') {
stds.out.write && stds.out.write(log_data);
if (pm2_env.pm_out_log_path !== 'NULL' && pm2_env.pm_out_log_path !== '/dev/null' && stds.out.write) {
stds.out.write(log_data, encoding, cb);
}
else if (cb) {
cb();
}

process.send({
Expand Down

0 comments on commit 1b0a89d

Please sign in to comment.