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
This commit is contained in:
parent
433613e267
commit
83397a69fc
2 changed files with 18 additions and 6 deletions
|
|
@ -4060,7 +4060,8 @@ proc gorge*(command: string, input = "", cache = ""): string {.
|
||||||
|
|
||||||
proc staticExec*(command: string, input = "", cache = ""): string {.
|
proc staticExec*(command: string, input = "", cache = ""): string {.
|
||||||
magic: "StaticExec".} = discard
|
magic: "StaticExec".} = discard
|
||||||
## Executes an external process at compile-time.
|
## Executes an external process at compile-time and returns its text output
|
||||||
|
## (stdout + stderr).
|
||||||
##
|
##
|
||||||
## If `input` is not an empty string, it will be passed as a standard input
|
## If `input` is not an empty string, it will be passed as a standard input
|
||||||
## to the executed program.
|
## to the executed program.
|
||||||
|
|
|
||||||
|
|
@ -239,8 +239,14 @@ proc cpDir*(`from`, to: string) {.raises: [OSError].} =
|
||||||
copyDir `from`, to
|
copyDir `from`, to
|
||||||
checkOsError()
|
checkOsError()
|
||||||
|
|
||||||
proc exec*(command: string) =
|
proc exec*(command: string) {.
|
||||||
## Executes an external process.
|
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:
|
log "exec: " & command:
|
||||||
if rawExec(command) != 0:
|
if rawExec(command) != 0:
|
||||||
raise newException(OSError, "FAILED: " & command)
|
raise newException(OSError, "FAILED: " & command)
|
||||||
|
|
@ -248,11 +254,16 @@ proc exec*(command: string) =
|
||||||
|
|
||||||
proc exec*(command: string, input: string, cache = "") {.
|
proc exec*(command: string, input: string, cache = "") {.
|
||||||
raises: [OSError], tags: [ExecIOEffect].} =
|
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:
|
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.
|
## Executes an external command with the current nim/nimble executable.
|
||||||
## ``Command`` must not contain the "nim " part.
|
## ``Command`` must not contain the "nim " part.
|
||||||
let c = selfExe() & " " & command
|
let c = selfExe() & " " & command
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue