Commit 8d644148
8d644148ccbbMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
Run single-string system() through the shell on Windows
The POSIX branch of sp_system_args already routes a 1-argument system("cmd ...") through /bin/sh -c so shell builtins and word splitting work. The Windows branch lacked the equivalent: it passed the whole command string to _spawnvp as an executable name, so system("echo hello") failed to find an "echo hello" binary -- echo is a cmd.exe builtin -- producing no output, a false return, and $? = -1.
Add an argc==1 fast path that calls C system(), which routes through cmd.exe /c on MSVCRT. MSVCRT system() returns the plain exit code, so store rc<<8 in sp_last_status to match the POSIX $? layout callers test.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- 8d644148ccbb
- Parent
- 7b32d151bdfd
lib/sp_system.cmodifiedView file
} fflush(NULL);#ifdef _WIN32 if (argc == 1) { /* Single-string form: run through the shell (cmd.exe) so builtins like `echo` and shell parsing work, mirroring the POSIX `/bin/sh -c` path. _spawnvp would instead try to locate the whole string as an .exe. */ int rc = system(argv[0]); if (rc == -1) { sp_last_status = -1; return FALSE; } /* MSVCRT system() returns the plain exit code; shift to match the POSIX `$?` layout the callers compare against. */ sp_last_status = rc << 8; return rc == 0 ? TRUE : FALSE; } char **quoted_argv = (char **)malloc(sizeof(char *) * (size_t)(argc + 1)); if (!quoted_argv) { sp_last_status = -1;