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

pm2 attach <pm_id> #2968

Closed
Unitech opened this issue Jun 26, 2017 · 5 comments
Closed

pm2 attach <pm_id> #2968

Unitech opened this issue Jun 26, 2017 · 5 comments

Comments

@Unitech
Copy link
Owner

Unitech commented Jun 26, 2017

Allow to attach to a process stdin (and stdout) in order to send commands.
This is very useful when you have implemented a kind of CLI in an application (IoT, electronic...).

How we fork a process:

 var cspr = spawn(command, args, {
          env      : pm2_env,
          detached : true,
          cwd      : pm2_env.pm_cwd || process.cwd(),
          stdio    : ['pipe', 'pipe', 'pipe', 'ipc']   //Same as fork() in node core
 });

https://github.com/Unitech/pm2/blob/master/lib/God/ForkMode.js#L94

Potential solution

Use Node.js readline via pm2 attach <proc_id> and at every new command (separated by a \n), send to PM2 daemon method that will do a `God.clusters_db[pm_id].stdin.write(CMD)

@vmarchaud thoughts?

@Unitech
Copy link
Owner Author

Unitech commented Jun 28, 2017

  • poc to write on forked process stdin
  • pm2 attach <pm_id>
  • pm2-runtime <app.js> --attach

Unitech added a commit that referenced this issue Jun 29, 2017
Unitech added a commit that referenced this issue Jul 14, 2017
@Unitech
Copy link
Owner Author

Unitech commented Jul 20, 2017

Published on PM2 2.6.0:

$ npm install pm2@latest -g
$ pm2 update
$ pm2 attach 0

@Unitech Unitech closed this as completed Jul 20, 2017
@GGYaX
Copy link

GGYaX commented Mar 29, 2018

pm2-runtime <app.js> --attach seems to work only for stdout but not stdin

inerc pushed a commit to inerc/pm2 that referenced this issue Feb 11, 2020
inerc pushed a commit to inerc/pm2 that referenced this issue Feb 11, 2020
inerc pushed a commit to inerc/pm2 that referenced this issue Feb 11, 2020
@naturecodevoid
Copy link

naturecodevoid commented Dec 31, 2020

was this feature removed? I can’t find it in the docs

edit: nevermind, found this file

@grantweii
Copy link

I'm getting this error when using npm prompt - which requests input from stdin ENXIO: no such device or address, open '/dev/tty'.

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

No branches or pull requests

4 participants