Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong operation of environment variable. #1124

Closed
ww24 opened this issue Mar 25, 2015 · 5 comments
Closed

Wrong operation of environment variable. #1124

ww24 opened this issue Mar 25, 2015 · 5 comments

Comments

@ww24
Copy link
Contributor

ww24 commented Mar 25, 2015

I think that this commit d5e731e is wrong operation of environment variable.

Example: https://github.com/Unitech/PM2/blob/0.12.8/lib/CLI.js#L961
process.env.PM2_PROGRAMMATIC === true
It absolutely not true, because environment variable is string.

@ww24 ww24 changed the title Please fix Wrong operation of environment variable. Mar 25, 2015
@jshkurti
Copy link
Contributor

Did this bug occured to you or you've been just reading PM2 code for fun ? :)
Anyway, should be fixed : 09d6b18

@ww24
Copy link
Contributor Author

ww24 commented Mar 25, 2015

I tried to call

var pm2 = require("pm2");
/* ~~~ */
var pm2_path = path.resolve(__dirname, "node_modules/.bin/pm2");
child_process.spawn(pm2_path, ["kill"], {stdio: "inherit"});

But I could not get stdout, stderr.

I found wrong operation of environment variable.

https://github.com/Unitech/PM2/blob/0.12.8/lib/Common.js#L169
https://github.com/Unitech/PM2/blob/0.12.8/lib/Common.js#L181

Thanks.

@Unitech
Copy link
Owner

Unitech commented Mar 25, 2015

Why do you require pm2 without using it? If you want to see the output, and dont use require pm2, just comment it.

If you use require pm2, you should do something like:

var pm2 = require("pm2");

pm2.connect(function() {
    pm2.kill(function() {
        pm2.disconnect();
    });
});

@ww24
Copy link
Contributor Author

ww24 commented Mar 25, 2015

Oh, That's right. I knew that.
But I want to create my command include pm2.

#!/usr/bin/env node
var pm2 = require("pm2");
var child_process = require("child_process");
var path = require("path");

if (process.argv[2] === "pm2") {
    var args = process.argv.slice(3);
    var pm2_path = path.resolve(__dirname, "node_modules/.bin/pm2");
    child_process.spawn(pm2_path, args, {stdio: "inherit"});
}

/* use pm2.connect (ellipsis) */

I can call pm2 command from my_command.

Ex: ./my_command pm2 kill

I can not get output because wrong operation of process.env.PM2_PROGRAMMATIC.

@ww24
Copy link
Contributor Author

ww24 commented Mar 25, 2015

If my PR accepted, I can call the following code and get outputs!

#!/usr/bin/env node
var pm2 = require("pm2");
var child_process = require("child_process");
var path = require("path");

if (process.argv[2] === "pm2") {
    process.env.PM2_PROGRAMMATIC = 'false'; //set false
    var args = process.argv.slice(3);
    var pm2_path = path.resolve(__dirname, "node_modules/.bin/pm2");
    child_process.spawn(pm2_path, args, {stdio: "inherit"});
}

/* use pm2.connect (ellipsis) */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants