diff --git a/lib/pipe-ipc.js b/lib/pipe-ipc.js index 236d998..862a06c 100644 --- a/lib/pipe-ipc.js +++ b/lib/pipe-ipc.js @@ -25,9 +25,9 @@ function PipeIPC() { } }; - this.createWriter = function() { + this.createWriter = function(iomode) { //this.writer = CreateObject("Scripting.FileSystemObject").CreateTextFile(this.path, true, true); - this.writer = CreateObject("Scripting.FileSystemObject").OpenTextFile(this.path, ForAppending, true, TristateTrue); + this.writer = CreateObject("Scripting.FileSystemObject").OpenTextFile(this.path, iomode, true, TristateTrue); }; this.closeWriter = function() { @@ -54,7 +54,8 @@ function PipeIPC() { while (!isWritten) { try { - this.createWriter(); + this.flush(); + this.createWriter(ForAppending); this._write(message); this.writer.Close(); isWritten = true; @@ -85,6 +86,21 @@ function PipeIPC() { return messages; }; + this.flush = function() { + var isFlushed = false; + + while (!isFlushed) { + try { + this.createWriter(ForWriting); + this._write(""); + this.writer.Close(); + isFlushed = true; + } catch (e) { + isFlushed = false; + } + } + }; + this.readText = function() { return this.read().join(' '); }; @@ -99,7 +115,7 @@ exports.create = function() { return new PipeIPC(); }; -exports.VERSIONINFO = "PIPE-based IPC Module (pipe-ipc.js) version 0.1.1"; +exports.VERSIONINFO = "PIPE-based IPC Module (pipe-ipc.js) version 0.1.2"; exports.AUTHOR = "Nathan Catswords "; exports.global = global; exports.require = require;