Reputation: 213
I have to show progress of node chid_process commands on UI. I am not able to track the progress of commands using any js lib like progress-bar. How can i show say "git clone" progress on UI so that user knows the status of the process ?
Upvotes: 0
Views: 1720
Reputation:
If you mean in general and not for functions you define specifically for this purpose and want to run separately as child process, you really can't unless the child process provides this information itself via for example STDOUT.
And if so, you can only grab this raw output for then having to parse it to find something you could use to indicate progress. This of course, has its own quirks as the output is typically buffered which require you to think through how you parse the buffer(ing).
On top of that you can run into cases where the output format or order changes in the future in such a way that your program no longer can find the key information it needs.
In the case of git
, there is really no progress per-se, only stages - which is fine and can act as a form of progress (stage 1 of 4 etc.).
To grab the output you would use something like:
const spawn = require("child_process").spawn;
const child = spawn("git" , ["clone", "https://some.rep"]);
child.stdout.on("data", data => {
// parse data here...
});
...
and the same for stderr
. See Node documentation for more details.
Upvotes: 3