mirror of
https://github.com/arun11299/cpp-subprocess.git
synced 2025-08-04 12:26:19 -04:00
Fix redirection from StdError on Windows (#96)
* Fix redirection from StdError on Windows * test: Add cross-platform test for error redirection
This commit is contained in:
parent
06858e5fd7
commit
40bcc2daa9
@ -1535,7 +1535,7 @@ inline void Popen::execute_process() noexcept(false)
|
||||
ZeroMemory(&siStartInfo, sizeof(STARTUPINFOW));
|
||||
siStartInfo.cb = sizeof(STARTUPINFOW);
|
||||
|
||||
siStartInfo.hStdError = this->stream_.g_hChildStd_OUT_Wr;
|
||||
siStartInfo.hStdError = this->stream_.g_hChildStd_ERR_Wr;
|
||||
siStartInfo.hStdOutput = this->stream_.g_hChildStd_OUT_Wr;
|
||||
siStartInfo.hStdInput = this->stream_.g_hChildStd_IN_Rd;
|
||||
|
||||
|
@ -19,3 +19,17 @@ foreach(test_file IN LISTS test_files)
|
||||
COPYONLY
|
||||
)
|
||||
endforeach()
|
||||
|
||||
|
||||
set(TEST_REDIRECTION_PYTHON_SCRIPT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/test_redirection.py)
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_redirection.cc.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/test_redirection.cc
|
||||
@ONLY
|
||||
)
|
||||
add_executable(test_redirection ${CMAKE_CURRENT_BINARY_DIR}/test_redirection.cc)
|
||||
target_link_libraries(test_redirection PRIVATE subprocess)
|
||||
add_test(
|
||||
NAME test_redirection
|
||||
COMMAND $<TARGET_FILE:test_redirection>
|
||||
)
|
||||
|
23
test/test_redirection.cc.in
Normal file
23
test/test_redirection.cc.in
Normal file
@ -0,0 +1,23 @@
|
||||
#include <subprocess.hpp>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
|
||||
using namespace subprocess;
|
||||
|
||||
int main() {
|
||||
auto p = Popen("python3 @TEST_REDIRECTION_PYTHON_SCRIPT_PATH@", output{PIPE}, error{PIPE});
|
||||
OutBuffer out_buf;
|
||||
ErrBuffer err_buf;
|
||||
std::tie(out_buf, err_buf) = p.communicate();
|
||||
std::string out{out_buf.buf.data()};
|
||||
std::string err{err_buf.buf.data()};
|
||||
|
||||
if (out.find("Hello message.") == std::string::npos) return EXIT_FAILURE;
|
||||
if (err.find("Hello message.") != std::string::npos) return EXIT_FAILURE;
|
||||
if (out.find("Error report.") != std::string::npos) return EXIT_FAILURE;
|
||||
if (err.find("Error report.") == std::string::npos) return EXIT_FAILURE;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
7
test/test_redirection.py
Executable file
7
test/test_redirection.py
Executable file
@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("Hello message.")
|
||||
print("Error report.", file=sys.stderr)
|
Loading…
x
Reference in New Issue
Block a user