Commit graph

18 commits

Author SHA1 Message Date
Tomás Andróil
7e80030a95
subprocess: check and handle fcntl(F_GETFD) failure
Add missing error check for fcntl(fd, F_GETFD, 0) in set_clo_on_exec.
Raise OSError on failure to align with existing FD_SETFD behavior.
This improves robustness in subprocess setup and error visibility.

Github-Pull: arun11299/cpp-subprocess#117
Rebased-From: 9974ff69cdd5fc1a2722cb63f006df9308628b35
2025-04-28 17:14:19 +01:00
Haowen Liu
e25ec7300c
subprocess: Proper implementation of wait() on Windows
This commit makes sure:
1. WaitForSingleObject returns with expected
code before proceeding.
2. Process handle is properly closed.

Github-Pull: arun11299/cpp-subprocess#116
Rebased-From: 625a8775791e62736f20f3fa3e6cc4f1b24aa89a
2025-04-27 17:23:38 +01:00
Hennadii Stepanov
bf8230d525
subprocess: Do not escape double quotes for command line arguments on Windows
* refactor: Guard `util::quote_argument()` with `#ifdef __USING_WINDOWS__`

The `util::quote_argument()` function is specific to Windows and is used
in code already guarded by `#ifdef __USING_WINDOWS__`.

* Do not escape double quotes for command line arguments on Windows

This change fixes the handling of double quotes and aligns the behavior
with Python's `Popen` class. For example:
```
>py -3
>>> import subprocess
>>> p = subprocess.Popen("cmd.exe /c dir \"C:\\Program Files\"", stdout=subprocess.PIPE, text=True)
>>> print(f"Captured stdout:\n{stdout}")
```

Currently, the same command line processed by the `quote_argument()`
function looks like `cmd.exe /c dir "\"C:\Program" "Files\""`, which is
broken.

With this change, it looks correct: `cmd.exe /c dir "C:\Program Files"`.

Github-Pull: arun11299/cpp-subprocess#113
Rebased-From: ed313971c04ac10dc006104aba07d016ffc6542a
2025-04-27 17:23:27 +01:00
Hennadii Stepanov
df7a52241f
subprocess: Avoid leaking POSIX name aliases beyond subprocess.h
The commit a32c0f3df4b6bcd1d2e93f19e8f380bb890cd507 introduced code to
silence MSVC's "warning C4996: The POSIX name for this item is
deprecated."

However, it exhibits several issues:
1. The aliases may leak into code outside the `subprocess.hpp` header.
2. They are unnecessarily applied when using the MinGW-w64 toolchain.
3. The fix is incomplete: downstream projects still see C4996 warnings.
4. The implementation lacks documentation.

This change addresses all of the above shortcomings.

Github-Pull: arun11299/cpp-subprocess#112
Rebased-From: 778543b2f2ca7f5d1c4f0241b635bbb265d750dd

Co-authored-by: Luke Dashjr <luke-jr+git@utopios.org>
2025-04-27 17:23:20 +01:00
Hennadii Stepanov
7ecb4e430a
subprocess: Fix cross-compiling with mingw toolchain
Github-Pull: arun11299/cpp-subprocess#99
Rebased-From: 34033d03deacfdba892a708b7d8092b4d9e5e889
2025-04-27 16:50:15 +01:00
Haowen Liu
9e8992bf8b
subprocess: Get Windows return code in wait()
Currently, wait() returns 0 on windows regardless
of the actual return code of processes.

Github-Pull: arun11299/cpp-subprocess#109
Rebased-From: 04b015a8e52ead4d8bb5f0eb486419c77e418a17
2025-04-27 16:47:04 +01:00
Haowen Liu
9888d0f511
subprocess: Fix string_arg when used with rref
When passing in a rvalue reference, compiler
considers it ambiguous between std::string and
std::string&&. Making one of them take a lvalue
reference makes compilers correctly pick the right
one depending on whether the passed in value binds
to a rvalue or lvalue reference.

Github-Pull: arun11299/cpp-subprocess#110
Rebased-From: 2d8a8eebb03e509840e2c3c755d1abf32d930f33
2025-04-27 16:43:42 +01:00
MarcoFalke
3333bae9b2
tidy: modernize-use-equals-default 2024-07-08 11:12:01 +02:00
Hennadii Stepanov
5a11d3023f
refactor, subprocess: Remove unused stream API calls 2024-05-10 14:58:27 +01:00
Hennadii Stepanov
05b6f8793c
refactor, subprocess: Remove unused Popen::child_created_ data member 2024-05-10 14:47:15 +01:00
Hennadii Stepanov
9e1ccf55e1
refactor, subprocess: Remove unused Popen::poll() 2024-05-10 14:47:07 +01:00
Hennadii Stepanov
24b53fc84a
refactor, subprocess: Remove Popen::pid() 2024-05-10 14:42:31 +01:00
Sebastian Falbesoner
8b52e7f628 update comments in cpp-subprocess (check_output references)
Remove obsolete `check_output` references in the comments and remove
the numbering of the Popen API methods, as they don't seem to provide a
value and just make diffs larger for future changes.
2024-04-28 14:18:06 +02:00
Sebastian Falbesoner
97f159776e remove unused method Popen::kill from cpp-subprocess 2024-04-28 14:17:14 +02:00
Sebastian Falbesoner
908c51fe4a remove commented out code in cpp-subprocess 2024-04-25 17:44:39 +02:00
Sebastian Falbesoner
ff79adbe05 remove unused templates from cpp-subprocess
The templates `is_ready`, `param_pack`, and `has_type` are not used
anywhere, so let's remove them.
2024-04-25 02:04:31 +02:00
Hennadii Stepanov
08f756bd37
Replace locale-dependent std::strerror with SysErrorString 2024-04-23 18:22:58 +01:00
Hennadii Stepanov
d8e4ba4d05
refactor: Rename subprocess.hpp to follow our header name conventions 2024-04-23 18:22:58 +01:00
Renamed from src/util/subprocess.hpp (Browse further)