mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-31 10:22:15 +00:00
#23992 The test case provided does not cover the Windows situation, I fixed it in this new PR. Fixed an issue where errorCode was always 0 when startProcess didn't use the poEvalCommand flag. Tthe sleep command might not be available in all Windows installations, so I skipped the relevant test. Added a test case, tested on my fedora and windows systems.
28 lines
684 B
Nim
28 lines
684 B
Nim
discard """
|
|
output: '''true
|
|
true'''
|
|
"""
|
|
|
|
import std/osproc
|
|
|
|
const command = "lsaaa -lah"
|
|
|
|
try:
|
|
let process = startProcess(command, options = {poUsePath})
|
|
discard process.waitForExit()
|
|
except OSError as e:
|
|
echo e.errorCode != 0
|
|
|
|
# `poEvalCommand`, invokes the system shell to run the specified command
|
|
try:
|
|
let process = startProcess(command, options = {poUsePath, poEvalCommand})
|
|
# linux
|
|
let exitCode = process.waitForExit()
|
|
echo exitCode != 0
|
|
except OSError as e:
|
|
# Because the implementation of `poEvalCommand` on different platforms is inconsistent,
|
|
# Linux will not throw an exception, but Windows will throw an exception
|
|
|
|
# windows
|
|
echo e.errorCode != 0
|