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

The windows version should use spawn with the detached option instead of execFile #35

Closed
henhen724 opened this issue Dec 29, 2019 · 0 comments

Comments

@henhen724
Copy link

This is obviously more of a suggestion than an issue.

One use of ps-list/tasklist is for daemons and services which need to check what processes are being run. When windows daemons spawn non-detached processes, windows will bring them to the foreground briefly, which obviously means that a daemon regularly using ps-list will have windows constantly popping up. This is probably an issue with either Windows, node child_process exec, or node daemonizers like forever and pm2, but it doesn't seem likely to be fixed.

The fix for this does not actually change the functionality for other users at all, so it shouldn't be a big deal.

I tested the following and worked for my application:
from index.js line 9

const windows = async () => {
  const bin = path.join(__dirname, 'fastlist.exe');
  const fullstdout = await new Promise((resolve, reject) => {
    const childprocess = spawn(bin, {maxBuffer: TEN_MEGABYTES, detached: true});
    var stdout = '';
    var stderr = '';
    childprocess.stdout.on('data', data => {
      stdout += data.toString();
    });
    childprocess.stderr.on('data', data => {
      stderr += data.toString();
    });
    childprocess.on('close', code => {
      if(code != 0)
        reject(new Error("FASTLIST THROUGH THE FOLLOWING ERRORS: ", stderr, "\nExit with code ", code));
      else{
        resolve(stdout);
      }
    });
  });

  return fullstdout
		.trim()
		.split('\r\n')
		.map(line => line.split('\t'))
		.map(([name, pid, ppid]) => ({
			name,
			pid: Number.parseInt(pid, 10),
			ppid: Number.parseInt(ppid, 10)
		}));
};

Obviously, nicer error messages could be added, but aside from that, this would fix this issue.

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

1 participant