diff options
Diffstat (limited to 'lib/pure/osproc.nim')
-rw-r--r-- | lib/pure/osproc.nim | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim index 0cf2171de..b2239b9c5 100644 --- a/lib/pure/osproc.nim +++ b/lib/pure/osproc.nim @@ -64,6 +64,7 @@ const poUseShell* {.deprecated.} = poUsePath ## Deprecated alias for poUsePath. proc execProcess*(command: string, + workingDir: string = "", args: openArray[string] = [], env: StringTableRef = nil, options: set[ProcessOption] = {poStdErrToStdOut, @@ -154,7 +155,7 @@ proc running*(p: Process): bool {.rtl, extern: "nosp$1", tags: [].} ## Returns true iff the process `p` is still running. Returns immediately. proc processID*(p: Process): int {.rtl, extern: "nosp$1".} = - ## returns `p`'s process ID. + ## returns `p`'s process ID. See also ``os.getCurrentProcessId()``. return p.id proc waitForExit*(p: Process, timeout: int = -1): int {.rtl, @@ -349,12 +350,13 @@ proc select*(readfds: var seq[Process], timeout = 500): int when not defined(useNimRtl): proc execProcess(command: string, + workingDir: string = "", args: openArray[string] = [], env: StringTableRef = nil, options: set[ProcessOption] = {poStdErrToStdOut, poUsePath, poEvalCommand}): TaintedString = - var p = startProcess(command, args=args, env=env, options=options) + var p = startProcess(command, workingDir=workingDir, args=args, env=env, options=options) var outp = outputStream(p) result = TaintedString"" var line = newStringOfCap(120).TaintedString @@ -1323,6 +1325,12 @@ proc execCmdEx*(command: string, options: set[ProcessOption] = { ## let (outp, errC) = execCmdEx("nim c -r mytestfile.nim") var p = startProcess(command, options=options + {poEvalCommand}) var outp = outputStream(p) + + # There is no way to provide input for the child process + # anymore. Closing it will create EOF on stdin instead of eternal + # blocking. + close inputStream(p) + result = (TaintedString"", -1) var line = newStringOfCap(120).TaintedString while true: @@ -1333,3 +1341,4 @@ proc execCmdEx*(command: string, options: set[ProcessOption] = { result[1] = peekExitCode(p) if result[1] != -1: break close(p) + |