summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorDominik Picheta <dominikpicheta@googlemail.com>2013-01-28 00:32:36 +0000
committerDominik Picheta <dominikpicheta@googlemail.com>2013-01-28 00:32:36 +0000
commitd9d98512e043c1bed44da7f81025046def325a26 (patch)
tree8c90e270a3e9e90b970668a5112185bb7de66028 /lib
parent0087828e126679b3e4cabecc81f0a04cafb1a4f2 (diff)
downloadNim-d9d98512e043c1bed44da7f81025046def325a26.tar.gz
Fixed osproc.execCmdEx; tester should now succeed.
Diffstat (limited to 'lib')
-rwxr-xr-xlib/pure/osproc.nim31
1 files changed, 15 insertions, 16 deletions
diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim
index 89914feeb..e627e73c8 100755
--- a/lib/pure/osproc.nim
+++ b/lib/pure/osproc.nim
@@ -242,7 +242,6 @@ when not defined(useNimRtl):
         result.string.add(line.string)
         result.string.add("\n")
       elif not running(p): break
-    close(outp)
     close(p)
 
 
@@ -647,20 +646,10 @@ elif not defined(useNimRtl):
       discard close(p_stdin[readIdx])
       discard close(p_stdout[writeIdx])
 
-    proc createStream(stream: var PStream, handle: var TFileHandle,
-                      fileMode: TFileMode) =
-      var f: TFile
-      if not open(f, handle, fileMode): OSError()
-      stream = newFileStream(f)
-
-    createStream(result.inStream, result.inputHandle, fmWrite)
-    createStream(result.outStream, result.outputHandle, fmRead)
-    createStream(result.errStream, result.errorHandle, fmRead)
-
   proc close(p: PProcess) =
-    close(p.inStream)
-    close(p.outStream)
-    close(p.errStream)
+    if p.inStream != nil: close(p.inStream)
+    if p.outStream != nil: close(p.outStream)
+    if p.errStream != nil: close(p.errStream)
     discard close(p.inputHandle)
     discard close(p.outputHandle)
     discard close(p.errorHandle)
@@ -701,13 +690,25 @@ elif not defined(useNimRtl):
     if p.exitCode == -3: result = -1
     else: result = p.exitCode.int shr 8
 
+  proc createStream(stream: var PStream, handle: var TFileHandle,
+                    fileMode: TFileMode) =
+    var f: TFile
+    if not open(f, handle, fileMode): OSError()
+    stream = newFileStream(f)
+
   proc inputStream(p: PProcess): PStream =
+    if p.inStream == nil:
+      createStream(p.inStream, p.inputHandle, fmWrite)
     return p.inStream
 
   proc outputStream(p: PProcess): PStream =
+    if p.outStream == nil:
+      createStream(p.outStream, p.outputHandle, fmRead)
     return p.outStream
 
   proc errorStream(p: PProcess): PStream =
+    if p.errStream == nil:
+      createStream(p.errStream, p.errorHandle, fmRead)
     return p.errStream
 
   proc csystem(cmd: cstring): cint {.nodecl, importc: "system".}
@@ -766,10 +767,8 @@ proc execCmdEx*(command: string, options: set[TProcessOption] = {
     else:
       result[1] = peekExitCode(p)
       if result[1] != -1: break
-  close(outp)
   close(p)
 
-
 when isMainModule:
   var x = execProcess("gcc -v")
   echo "ECHO ", x