diff options
Diffstat (limited to 'src/extern')
-rw-r--r-- | src/extern/runproc.nim | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/extern/runproc.nim b/src/extern/runproc.nim index c49d98db..fa1ed9bc 100644 --- a/src/extern/runproc.nim +++ b/src/extern/runproc.nim @@ -1,3 +1,4 @@ +import streams import posix import display/term @@ -27,3 +28,15 @@ proc runProcess*(term: Terminal, cmd: string, wait = false): bool = if wait: term.anyKey() term.restart() + +# Run process, and capture its output. +proc runProcessCapture*(term: Terminal, cmd: string, outs: var string): bool = + let file = popen(cmd, "r") + if file == nil: + return false + let fs = newFileStream(file) + outs = fs.readAll() + let rv = pclose(file) + if rv == -1: + return false + return rv == 0 |