texecps.nim 821 B

123456789101112131415161718192021222324252627
  1. import osproc, streams, strutils, os
  2. const NumberOfProcesses = 13
  3. var gResults {.threadvar.}: seq[string]
  4. proc execCb(idx: int, p: Process) =
  5. let exitCode = p.peekExitCode
  6. if exitCode < len(gResults):
  7. gResults[exitCode] = p.outputStream.readAll.strip
  8. when true:
  9. if paramCount() == 0:
  10. gResults = newSeq[string](NumberOfProcesses)
  11. var checks = newSeq[string](NumberOfProcesses)
  12. var commands = newSeq[string](NumberOfProcesses)
  13. for i in 0..len(commands) - 1:
  14. commands[i] = getAppFileName() & " " & $i
  15. checks[i] = $i
  16. let cres = execProcesses(commands, options = {poStdErrToStdOut},
  17. afterRunEvent = execCb)
  18. doAssert(cres == len(commands) - 1)
  19. doAssert(gResults == checks)
  20. else:
  21. echo paramStr(1)
  22. programResult = parseInt(paramStr(1))