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

programmatic examples #857

Closed
sandro-pasquali opened this issue Dec 1, 2014 · 5 comments
Closed

programmatic examples #857

sandro-pasquali opened this issue Dec 1, 2014 · 5 comments

Comments

@sandro-pasquali
Copy link

Are there any programmatic examples that go into more depth? Specifically, how do I pass arguments to the target script -- i've tried nodeArgs, scriptArgs, env, node_args, script_args -- and i don't see those values anywhere in the process.

Great tool, looking forward to using it.

@soyuka
Copy link
Collaborator

soyuka commented Dec 1, 2014

Is this what you're looking for ?

@sandro-pasquali
Copy link
Author

I looked at that. It seems to indicate that the second argument to #start is a map of options, and that (I think) these are the options for passing arguments to the script: nodeArgs(arr), scriptArgs(arr)... yet, when I set those pm2.start('somescript.js', { name: 'test', scriptArgs : ['foo', 'bar'] } ...) I'm not catching them via process.argv in the target script.

I'm assuming it is modeled like the second argument to child_process.fork('script', [args]). It doesn't seem to be.

Thanks for the help. I fear i'm missing something obvious.

@soyuka
Copy link
Collaborator

soyuka commented Dec 1, 2014

I'm using pm2.startJson which allows you to pass everything from a json declaration.

When you're using pm2.start you're basically calling this function, nodeArgs are the arguments to pass to node instance, scriptArgs should be your script arguments.

I'm also seeing rawArgs (l57), those are usually called from the command line: pm2 start myApp.js -- var=test - process.argv will have a property var with value test.

@sandro-pasquali
Copy link
Author

Thanks. After playing around with both solutions and reading the code closely I've achieved what I wanted to achieve.

As the child (fork) process should have a communication channel (as per the node spec for #fork), I was wondering as well how to access that? To achieve something like the follow, where the forked process can send a message to its master:

pm2.start(...,...,function(err, proc) {
  proc.on('message', function(msg) { ... }
})

@joshgummersall
Copy link

@sandro-pasquali any chance you could elaborate on the solution you came up with?

Unitech pushed a commit that referenced this issue Jan 12, 2015
@Unitech Unitech closed this as completed Jan 12, 2015
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

4 participants