Open srele96 opened 2 years ago
Notes:
options.stdio = 'inherit'
will print the stuff from the executed command in current terminal.Point 1 is solvable with https://nodejs.org/api/child_process.html#optionsdetached. That opens questions:
Long running detached processes get spawned in new OS native terminal.
Run detached process like here https://nodejs.org/api/child_process.html#optionsdetached
const { openSync } = /* */ require('fs');
const { spawn } = /* */ require('child_process');
const out = openSync('./out.log', 'a');
const err = openSync('./err.log', 'a');
// watch express server using nodemon
const subprocess = spawn('yarn start:serve-data', {
cwd: 'C:\\Users\\Srecko\\Documents\\MyProjects\\Private\\webstorm-container\\sk-experiments\\tcp-packages',
detached: true,
shell: true,
stdio: ['ignore', out, err],
});
subprocess.unref();
Detached process should behave exactly the same as any terminal.
We can't use ignore for stdin like stdio: ['ignore', out, err]
. CTRL+C
does not terminate it.
Is it a problem if new detached process runs as NodeJS? (It has the NodeJS icon).
So far i know about the two types of processes.
A process like nodemon app.js
. Such process watches file changes and shows command line output.
Another type is echo hello
or mkdir test
. Those exit immediately, but may have command line output like echo.
I believe we shouldn't treat them differently. Both are the same, but one exits faster.
That means we need to handle processes that are:
Running process interfere with our cli. The cli is a parent process. Parent process waits for child processes to exit.
We currently can't handle user interaction while the child processes are running.
While child processes are running, so is cli. Terefore we need to treat that case accordingly.
Whenever we run commands, we should expect their process to be long running. Actually, we shouldn't even think how long they run. All of them behave the same, whether it's a millisecond, second, minute or more.
Therefore, we should behave as process-watcher.
The cli is in two states:
The watched processes are:
User should be able to use the cli in both states.
Learn how does spawn
run command on any OS.
That may provide a way to run command in new shell on any OS.
Read information from: https://github.com/srele96/run-them-all/issues/6!
NodeJS
spawn
is better for long running processes. It also providesoptions.detached
which (per my understanding) allows us to:options.detached
close?options.detached
create memory leak?Things to add: