about summary refs log tree commit diff stats
path: root/src/extern/runproc.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-09-25 02:08:33 +0200
committerbptato <nincsnevem662@gmail.com>2023-09-25 02:08:33 +0200
commit463499131a1b4ca41fea56030f77f4794cdca071 (patch)
tree54f2efea637c9762711db4140ff42ae833a0900e /src/extern/runproc.nim
parent790e937795746563246808abaf4b0b25f4a5d0fe (diff)
downloadchawan-463499131a1b4ca41fea56030f77f4794cdca071.tar.gz
Add M-p as "load page on clipboard"
Diffstat (limited to 'src/extern/runproc.nim')
-rw-r--r--src/extern/runproc.nim13
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