Files
Nim/tests/osproc/tnoexe.nim
握猫猫 5e8cd318ef Fix linux start process errorCode always 0 (#24001)
#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.
2024-08-28 20:52:00 +02:00

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