texecps.nim 854 B

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