@@ -83,10 +83,34 @@ int run(
83
83
const std::string &std_error)
84
84
{
85
85
#ifdef _WIN32
86
- // we don't support stdin/stdout/stderr redirection on Windows
87
- PRECONDITION (std_input.empty ());
88
- PRECONDITION (std_output.empty ());
89
- PRECONDITION (std_error.empty ());
86
+ // we use the cmd.exe shell to do stdin/stdout/stderr redirection on Windows
87
+ if (!std_input.empty () || !std_output.empty () || !std_error.empty ())
88
+ {
89
+ std::vector<std::string> new_argv = argv;
90
+ new_argv.insert (new_argv.begin (), " cmd.exe" );
91
+ new_argv.insert (new_argv.begin () + 1 , " /c" );
92
+
93
+ if (!std_input.empty ())
94
+ {
95
+ new_argv.push_back (" <" );
96
+ new_argv.push_back (std_input);
97
+ }
98
+
99
+ if (!std_output.empty ())
100
+ {
101
+ new_argv.push_back (" >" );
102
+ new_argv.push_back (std_output);
103
+ }
104
+
105
+ if (!std_error.empty ())
106
+ {
107
+ new_argv.push_back (" 2>" );
108
+ new_argv.push_back (std_error);
109
+ }
110
+
111
+ // this is recursive
112
+ return run (new_argv[0 ], new_argv, " " , " " , " " );
113
+ }
90
114
91
115
// unicode version of the arguments
92
116
std::vector<std::wstring> wargv;
@@ -103,12 +127,12 @@ int run(
103
127
104
128
_argv[argv.size ()]=NULL ;
105
129
106
- // warning: the arguments may still need escaping
130
+ // warning: the arguments may still need escaping,
131
+ // as windows will concatenate the argv strings back together,
132
+ // separating them with spaces
107
133
108
134
std::wstring wide_what=widen (what);
109
-
110
135
int status=_wspawnvp (_P_WAIT, wide_what.c_str (), _argv.data ());
111
-
112
136
return status;
113
137
114
138
#else
0 commit comments