summary refs log tree commit diff stats
path: root/lib/pure/osproc.nim
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-11-29 01:24:58 +0100
committerAraq <rumpf_a@web.de>2011-11-29 01:24:58 +0100
commite261a88d074038391574402e88737af4752a1041 (patch)
tree6dfbeb266de2f0b91f0a7f416d6538521ca0892f /lib/pure/osproc.nim
parenta489161b1629b2b7347521c8ec67a0e5e812ef6a (diff)
downloadNim-e261a88d074038391574402e88737af4752a1041.tar.gz
further steps to get rid of deprecated endOfFile and readLine
Diffstat (limited to 'lib/pure/osproc.nim')
-rwxr-xr-xlib/pure/osproc.nim23
1 files changed, 15 insertions, 8 deletions
diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim
index e01953e85..dc107b382 100755
--- a/lib/pure/osproc.nim
+++ b/lib/pure/osproc.nim
@@ -160,7 +160,7 @@ proc execProcesses*(cmds: openArray[string],
   ## that execute in parallel. The highest return value of all processes
   ## is returned.
   when defined(posix):
-    # poParentStreams causes problems on Posix, so we disable it simply:
+    # poParentStreams causes problems on Posix, so we simply disable it:
     var options = options - {poParentStreams}
   
   assert n > 0
@@ -218,12 +218,16 @@ when not defined(useNimRtl):
     var p = startCmd(command, options=options)
     var outp = outputStream(p)
     result = TaintedString""
-    while running(p) or not atEnd(outp):
-      result.string.add(outp.readLine().string)
-      result.string.add("\n")
+    var line = newStringOfCap(120).TaintedString
+    while true:
+      if outp.readLine(line):
+        result.string.add(line.string)
+        result.string.add("\n")
+      elif not running(p): break
     close(outp)
     close(p)
 
+
 when defined(Windows) and not defined(useNimRtl):
   # We need to implement a handle stream for Windows:
   type
@@ -718,11 +722,14 @@ proc execCmdEx*(command: string, options: set[TProcessOption] = {
   var p = startCmd(command, options)
   var outp = outputStream(p)
   result = (TaintedString"", -1)
+  var line = newStringOfCap(120).TaintedString
   while true:
-    if result[1] == -1: result[1] = peekExitCode(p)
-    if result[1] != -1 and atEnd(outp): break
-    result[0].string.add(outp.readLine().string)
-    result[0].string.add("\n")
+    if outp.readLine(line):
+      result[0].string.add(line.string)
+      result[0].string.add("\n")
+    else:
+      result[1] = peekExitCode(p)
+      if result[1] != -1: break
   close(outp)
   close(p)