osproc.execCmdEx now takes an optional input for stdin, env, workingDir (#14211)

* `osproc.execCmdEx` now takes an optional `input` for stdin

* execCmdEx now also takes an optional ``workingDir` and `env`
This commit is contained in:
Timothee Cour
2020-05-13 04:45:36 -07:00
committed by GitHub
parent 1648f1dd99
commit 041ee92bba
4 changed files with 50 additions and 13 deletions

View File

@@ -1,7 +1,7 @@
# test the osproc module
import stdtest/specialpaths
import "../.." / compiler/unittest_light
import "$nim" / compiler/unittest_light
when defined(case_testfile): # compiled test file for child process
from posix import exitnow
@@ -119,3 +119,16 @@ else:
var result = startProcessTest("nim r --hints:off -", options = {}, input = "echo 3*4")
doAssert result == ("12\n", 0)
import std/strtabs
block execProcessTest:
var result = execCmdEx("nim r --hints:off -", options = {}, input = "echo 3*4")
stripLineEnd(result[0])
doAssert result == ("12", 0)
doAssert execCmdEx("ls --nonexistant").exitCode != 0
when false:
# bug: on windows, this raises; on posix, passes
doAssert execCmdEx("nonexistant").exitCode != 0
when defined(posix):
doAssert execCmdEx("echo $FO", env = newStringTable({"FO": "B"})) == ("B\n", 0)
doAssert execCmdEx("echo $PWD", workingDir = "/") == ("/\n", 0)