Ability to read the stdout buffer line-by-line
See original GitHub issueFor example, with exec('...', { silent: false });
within a gulp
stream, you’ll get this:
nathanbrauer@macthan:~/Web/git/Component-Core$ gulp compile:styles
[18:33:08] Using gulpfile ~/Web/git/Component-Core/gulpfile.js
[18:33:08] Starting 'compile:styles'...
write build/brand.css (0.713s)
write build/brand.css.map
[18:33:10] Finished 'compile:styles' after 1.17 s
Ideally, each of the lines (starting with write build/brand.css...
) would also conform to gulp’s logging (gutils.log(...)
). But the only way to do that, currently, is to wait for the entire buffer to end, then parse every line on your own. This means that the timestamps are completely wrong which makes it pointless… (but at least it’s prettier 😉):
var output = exec('...', { silent: true }).output,
output_lines = output.replace(/^\s+|\s+$/,'').split(/[\n\r]+/),// Trims the output and returns it split into an array of lines
log_line;
if (output) {
for (log_line = 0; log_line < output_lines.length; ++log_line) {
gutil.log(log_indent,output_lines[log_line]);
}
}
Here’s a real example: https://github.com/Marketera/gulp-composer/blob/master/index.js#L28
Ideally we’d be able to do something along the lines of…
var cmd = exec('composer install', {
silent: true,
onPrint: function(line){
gutil.log(line);
}
});
// ...which is basically the same as:
var cmd = exec('composer install', {
silent: true,
onPrint: gutil.log
});
// ...the default behavior, essentially being:
var cmd = exec('composer install', {
//...
onPrint: console.log
});
Some kind of way to “CTRL+C
” should also be included…
var cmd = exec('composer install', {
silent: true,
onPrint: function(line){
if (is_something_bad(line)) {
stream.emit('error', new gutil.PluginError('exec', "I didn't like this line: " + line));
}
gutil.log(line);
}
});
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Force line-buffering of stdout in a pipeline - unix - Stack Overflow
I think the right command if you read the man page is unbuffer ./a | tee output.txt . That's what worked for me...
Read more >Read process output line by line - Emacs Stack Exchange
I have a subprocess doing work in the background, and printing a line every time it completes a task. There are many such...
Read more >4 ways to read file line by line in Node.js
Learn how to read file line by line in Node.js with sync and async methods using native and NPM modules.
Read more >Line-based text processing in bash - zzz.buzz
Recently, I've been writing a script to parse the output of ping, ... grep processes input line by line, and when specified --line-buffered...
Read more >How to read a file line by line using node.js ? - GeeksforGeeks
The ability to read a file line by line allows us to read large files ... createReadStream('source_to_file'), output: process.stdout, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@nathanbrauer @tminglei
Would this section of the docs help you do what you want to achieve? It looks like you can get the results in real-time, chunk by chunk. Then it’s just up to you to parse for a newline (or whatever you need) and do something with the line of text.
Thanks - I’ll take a look at this is a week or so.