tnoexe.nim 684 B

12345678910111213141516171819202122232425262728
  1. discard """
  2. output: '''true
  3. true'''
  4. """
  5. import std/osproc
  6. const command = "lsaaa -lah"
  7. try:
  8. let process = startProcess(command, options = {poUsePath})
  9. discard process.waitForExit()
  10. except OSError as e:
  11. echo e.errorCode != 0
  12. # `poEvalCommand`, invokes the system shell to run the specified command
  13. try:
  14. let process = startProcess(command, options = {poUsePath, poEvalCommand})
  15. # linux
  16. let exitCode = process.waitForExit()
  17. echo exitCode != 0
  18. except OSError as e:
  19. # Because the implementation of `poEvalCommand` on different platforms is inconsistent,
  20. # Linux will not throw an exception, but Windows will throw an exception
  21. # windows
  22. echo e.errorCode != 0