mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-19 07:21:19 +00:00
Add workingDir parameter to execProcess and test (#9549)
* Add workingDir parameter to execProcess * Fix tests/stdlib/tosproc.nim compile error * Suppress output from tosproc.nim
This commit is contained in:
@@ -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,
|
||||
@@ -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
|
||||
|
||||
8
tests/stdlib/osproctest.nim
Normal file
8
tests/stdlib/osproctest.nim
Normal file
@@ -0,0 +1,8 @@
|
||||
# This is test program for the osproc module.
|
||||
|
||||
import os
|
||||
|
||||
echo getCurrentDir()
|
||||
|
||||
for i in 1..paramCount():
|
||||
echo paramStr(i)
|
||||
24
tests/stdlib/tosproc.nim
Normal file
24
tests/stdlib/tosproc.nim
Normal file
@@ -0,0 +1,24 @@
|
||||
discard """
|
||||
file: "tospaths.nim"
|
||||
output: ""
|
||||
"""
|
||||
# test the osproc module
|
||||
|
||||
import os, osproc
|
||||
|
||||
block execProcessTest:
|
||||
let dir = parentDir(currentSourcePath())
|
||||
let (outp, err) = execCmdEx("nim c " & quoteShell(dir / "osproctest.nim"))
|
||||
doAssert err == 0
|
||||
let exePath = dir / addFileExt("osproctest", ExeExt)
|
||||
let outStr1 = execProcess(exePath, workingDir=dir, args=["foo", "b A r"], options={})
|
||||
doAssert outStr1 == dir & "\nfoo\nb A r\n"
|
||||
|
||||
const testDir = "t e st"
|
||||
createDir(testDir)
|
||||
doAssert dirExists(testDir)
|
||||
let outStr2 = execProcess(exePath, workingDir=testDir, args=["x yz"], options={})
|
||||
doAssert outStr2 == absolutePath(testDir) & "\nx yz\n"
|
||||
|
||||
removeDir(testDir)
|
||||
removeFile(exePath)
|
||||
Reference in New Issue
Block a user