diff --git a/lib/pure/os.nim b/lib/pure/os.nim index 969a549de1640..32fa2885eaceb 100644 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -1287,13 +1287,16 @@ proc moveFile*(source, dest: string) {.rtl, extern: "nos$1", discard tryRemoveFile(dest) raise -proc exitStatusLikeShell*(status: cint): cint {.noNimScript.} = +proc exitStatusLikeShell*(status: cint): cint = ## converts exit code from `c_system` into a shell exit code - if WIFSIGNALED(status): - # like the shell! - 128 + WTERMSIG(status) + when defined(posix) and not weirdTarget: + if WIFSIGNALED(status): + # like the shell! + 128 + WTERMSIG(status) + else: + WEXITSTATUS(status) else: - WEXITSTATUS(status) + status proc execShellCmd*(command: string): int {.rtl, extern: "nos$1", tags: [ExecIOEffect], noNimScript.} = @@ -1303,12 +1306,8 @@ proc execShellCmd*(command: string): int {.rtl, extern: "nos$1", ## line arguments given to program. The proc returns the error code ## of the shell when it has finished. The proc does not return until ## the process has finished. To execute a program without having a - ## shell involved, use the `execProcess` proc of the `osproc` - ## module. - when defined(posix): - result = exitStatusLikeShell(c_system(command)) - else: - result = c_system(command) + ## shell involved, use `osproc.execProcess`. + result = exitStatusLikeShell(c_system(command)) # Templates for filtering directories and files when defined(windows) and not weirdTarget: diff --git a/tests/stdlib/tosproc.nim b/tests/stdlib/tosproc.nim index 55d4659f71228..72f0e1060d350 100644 --- a/tests/stdlib/tosproc.nim +++ b/tests/stdlib/tosproc.nim @@ -1,10 +1,7 @@ -discard """ - output: "" -""" # test the osproc module -import compiler/unittest_light import std/special_paths +import "../.." / compiler/unittest_light when defined(case_testfile): # compiled test file for child process from posix import exitnow @@ -75,7 +72,8 @@ else: runTest("c_exit2_139", 139) runTest("quit_139", 139) runTest("exit_array", 1) - runTest("exit_recursion", SIGSEGV.int + 128) # bug #10273: was returning 0 + when defined(posix): # on windows, -1073741571 + runTest("exit_recursion", SIGSEGV.int + 128) # bug #10273: was returning 0 assertEquals exitStatusLikeShell(SIGSEGV), SIGSEGV + 128.cint