Merge branch 'nexecProcesses' of https://github.com/cheatfate/Nim into cheatfate-nexecProcesses

This commit is contained in:
Andreas Rumpf 2017-12-01 02:06:51 +01:00
commit 8646a56738
2 changed files with 114 additions and 56 deletions

32
tests/osproc/texecps.nim Normal file
View file

@ -0,0 +1,32 @@
discard """
file: "texecps.nim"
output: ""
"""
import osproc, streams, strutils, os
const NumberOfProcesses = 13
var gResults {.threadvar.}: seq[string]
proc execCb(idx: int, p: Process) =
let exitCode = p.peekExitCode
if exitCode < len(gResults):
gResults[exitCode] = p.outputStream.readAll.strip
when isMainModule:
if paramCount() == 0:
gResults = newSeq[string](NumberOfProcesses)
var checks = newSeq[string](NumberOfProcesses)
var commands = newSeq[string](NumberOfProcesses)
for i in 0..len(commands) - 1:
commands[i] = getAppFileName() & " " & $i
checks[i] = $i
let cres = execProcesses(commands, options = {poStdErrToStdOut},
afterRunEvent = execCb)
doAssert(cres == len(commands) - 1)
doAssert(gResults == checks)
else:
echo paramStr(1)
programResult = parseInt(paramStr(1))