Write to another already running process stdin from Node.js without starting from inside

StackOverflow https://stackoverflow.com/questions/23598843

  •  20-07-2023
  •  | 
  •  

سؤال

I have a program that isn't started from inside Node.js, so I cannot use spawn'd stdin to write to. I have the PID of the process that is listening for stdin input, how can I write to it using my node code?

I always see code examples using child_process module, and my use case is different.

هل كانت مفيدة؟

المحلول

On Linux you should be able to write to '/proc/' + pid + '/fd/0'. However this isn't portable.

نصائح أخرى

If you have the process id then one can use ptrace or one of its variants: strace or ltrace to control, manipulate, and view process information and communication.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top