summary refs log tree commit diff stats
path: root/lib/system
diff options
context:
space:
mode:
authorFabian Keller <bluenote10@users.noreply.github.com>2019-08-13 07:41:08 +0200
committerMiran <narimiran@disroot.org>2019-08-13 07:41:08 +0200
commit83397a69fc12bdee6b71d8274c0c191bad1e890e (patch)
tree1adfbdbea5a3d0ed9e1f96324b8194a8eabfe6dd /lib/system
parent433613e2675064583ee5055d47aa89a43184e7f2 (diff)
downloadNim-83397a69fc12bdee6b71d8274c0c191bad1e890e.tar.gz
Consistent behavior of exec; Improved docs around exec, staticExec, gorgeEx, etc. (#10967)
* improved docs around exec, staticExec, gorgeEx, etc.
* incorporate review comment; made behavior of exec consistent
Diffstat (limited to 'lib/system')
-rw-r--r--lib/system/nimscript.nim21
1 files changed, 16 insertions, 5 deletions
diff --git a/lib/system/nimscript.nim b/lib/system/nimscript.nim
index 3411f1e6e..6f795d075 100644
--- a/lib/system/nimscript.nim
+++ b/lib/system/nimscript.nim
@@ -239,8 +239,14 @@ proc cpDir*(`from`, to: string) {.raises: [OSError].} =
     copyDir `from`, to
     checkOsError()
 
-proc exec*(command: string) =
-  ## Executes an external process.
+proc exec*(command: string) {.
+  raises: [OSError], tags: [ExecIOEffect].} =
+  ## Executes an external process. If the external process terminates with
+  ## a non-zero exit code, an OSError exception is raised.
+  ##
+  ## **Note:** If you need a version of ``exec`` that returns the exit code
+  ## and text output of the command, you can use `system.gorgeEx
+  ## <system.html#gorgeEx,string,string,string>`_.
   log "exec: " & command:
     if rawExec(command) != 0:
       raise newException(OSError, "FAILED: " & command)
@@ -248,11 +254,16 @@ proc exec*(command: string) =
 
 proc exec*(command: string, input: string, cache = "") {.
   raises: [OSError], tags: [ExecIOEffect].} =
-  ## Executes an external process.
+  ## Executes an external process. If the external process terminates with
+  ## a non-zero exit code, an OSError exception is raised.
   log "exec: " & command:
-    echo staticExec(command, input, cache)
+    let (output, exitCode) = gorgeEx(command, input, cache)
+    if exitCode != 0:
+      raise newException(OSError, "FAILED: " & command)
+    echo output
 
-proc selfExec*(command: string) =
+proc selfExec*(command: string) {.
+  raises: [OSError], tags: [ExecIOEffect].} =
   ## Executes an external command with the current nim/nimble executable.
   ## ``Command`` must not contain the "nim " part.
   let c = selfExe() & " " & command