mirror of
https://github.com/atom/atom.git
synced 2026-02-11 07:05:11 -05:00
Add bufferLines option to ChildProcess.exec
It ensures that stdout and stderr callbacks are triggered with whole lines
This commit is contained in:
@@ -8,6 +8,11 @@ module.exports =
|
||||
class ChildProccess
|
||||
@exec: (command, options={}) ->
|
||||
deferred = $.Deferred()
|
||||
|
||||
if options.bufferLines
|
||||
options.stdout = @bufferLines(options.stdout) if options.stdout
|
||||
options.stderr = @bufferLines(options.stderr) if options.stderr
|
||||
|
||||
$native.exec command, options, (exitStatus, stdout, stdin) ->
|
||||
if error != 0
|
||||
error = new Error("Exec failed (#{exitStatus}) command '#{command}'")
|
||||
@@ -18,3 +23,11 @@ class ChildProccess
|
||||
|
||||
deferred
|
||||
|
||||
@bufferLines: (callback) ->
|
||||
buffered = ""
|
||||
(data) ->
|
||||
buffered += data
|
||||
lastNewlineIndex = buffered.lastIndexOf('\n')
|
||||
if lastNewlineIndex >= 0
|
||||
callback(buffered.substring(0, lastNewlineIndex + 1))
|
||||
buffered = buffered.substring(lastNewlineIndex + 1)
|
||||
|
||||
Reference in New Issue
Block a user