passenv.nim 630 B

123456789101112131415161718192021222324252627282930313233
  1. discard """
  2. file: "passenv.nim"
  3. output: "123"
  4. targets: "c cpp objc"
  5. """
  6. import osproc, os, strtabs
  7. # Checks that the environment is passed correctly in startProcess
  8. # To do that launches a copy of itself with a new environment.
  9. if paramCount() == 0:
  10. # Parent process
  11. let env = newStringTable()
  12. env["A"] = "1"
  13. env["B"] = "2"
  14. env["C"] = "3"
  15. let p = startProcess(
  16. getAppFilename(),
  17. args = @["child"],
  18. env = env,
  19. options = {poStdErrToStdOut, poUsePath, poParentStreams}
  20. )
  21. discard p.waitForExit
  22. else:
  23. # Child process
  24. # should output "123"
  25. echo getEnv("A") & getEnv("B") & getEnv("C")