I am writing a simple (ISH) application that allows an internal system at work which is a per process (rsync To be used) from a remote server using any other remote server using a rest call.
I am quite familiar with the familiar structure already, and have just begun experimenting with the child_process library, and have stumbled upon a small problem. / P>
I have successfully started rsync processes using node's childProcess.spawn ()
, my problem is that rsync carriage return instead of a new line (\ r) With its progress output to line buffer (\ n). As a result, STDOUT event, process.stdout.on ('data', {})
is said once before saying that it is establishing the transfer, and after that the copy ends Once done, STDOUT data is not flavored on the carriage return, as a progress update, only a new line when the job ends.
The latest version of rsync (3.1.0) to switch output buffer has a switch \ r instead of \ r, but unfortunately, the company I work on does this version Will not adopt for a long time.
I am creating and reading child_process in a normal way ....
var doCopy = function (onFinish) {var process = childProcess.spawn ('ssh ', [Source.user + "@" + source.host, "rsync", "-avz", "--progress", source.path + source.file, "-e ssh", dest.user + "@ "+ Dest.host +": "+ dest.path]); Process.on ('error', function (error) {console.log ("ERR:" + error.code);}) process.stdout.on ('data', function (data) {console.log ("OUT : "+ Data);}); Process.stderr.on ('data', function (data) {console.log ("ERR:" + data);}); Process.on ('close', function (code) {console.log ("FIN:" + code); if (onfinish) {onFinish (code);}}); }
.. and the console output is ....
Out: Creating File List ... Out to Out File 1: Test4 MP3 32,768 0% 0.00 KB / s 00:00 169 7, 38,240 32% 161.84 MB / s 0:00:02 338,165,760 64% 161.32 Mb / s 0:00:01 504,692,736 96% 160.53 MB / s : 00: 00 524,288,000 100% 160.35 MB / s: 00:03 (XFR # 1, to-chuck = 0/1) Out: 469 bytes of 49,949 bytes 113,334.44 bytes / second total size 524,288,000 speed You can see that stdout.on ('data') is only called when the rsync produces a new line (where 'ot is 1,028.01 FIN: 0
. 'is).
My question is, can I change it? Maybe when a \ r occurs, then do the stream flush through a change? Then I can rotate the line again and again offer a progress update.
Deny it, I think my only other option will give the egg to another process to monitor the growing file?
Help / advice is highly appreciated.
I have found a very good module which was actually trying to get me somebody Also allows the character to delimit the stdout buffer (in my case '\ r') and trigger a new studio event to handle the data. Like ....
var splitter = process.stdout.pipe (streamspiller ("\ r")); Splitter.on ('token', function (data) {console.log ("out:" + data);}); Splitter.on ('done', function (data) {console.log ("full:" + data);});
No comments:
Post a Comment