@@ -183,6 +183,12 @@ static void allocBuffer(uv_handle_t* handle, size_t suggestedSize, uv_buf_t* buf
183
183
}
184
184
}
185
185
186
+ const std::string kStdioKindDefault = " default" ;
187
+ const std::string kStdioKindInherit = " inherit" ;
188
+ const std::string kStdioKindNone = " none" ;
189
+ // TODO: add forwarding
190
+ // const std::string kStdioKindForward = "forward";
191
+
186
192
int run (lua_State* L)
187
193
{
188
194
std::vector<std::string> args;
@@ -210,6 +216,7 @@ int run(lua_State* L)
210
216
bool useShell = false ;
211
217
std::string customShell;
212
218
std::string cwd;
219
+ std::string stdioKind;
213
220
std::map<std::string, std::string> env;
214
221
215
222
if (lua_istable (L, 2 ))
@@ -233,6 +240,14 @@ int run(lua_State* L)
233
240
234
241
lua_pop (L, 1 );
235
242
243
+ lua_getfield (L, 2 , " stdio" );
244
+ if (lua_isstring (L, -1 ))
245
+ {
246
+ stdioKind = lua_tostring (L, -1 );
247
+ // TODO: support stdin and separate stdout/stderr kinds
248
+ }
249
+ lua_pop (L, 1 );
250
+
236
251
lua_getfield (L, 2 , " env" );
237
252
if (lua_istable (L, -1 ))
238
253
{
@@ -339,12 +354,31 @@ int run(lua_State* L)
339
354
340
355
options.stdio_count = 3 ;
341
356
uv_stdio_container_t stdio[3 ];
342
- stdio[0 ].flags = UV_INHERIT_FD;
343
- stdio[0 ].data .fd = 0 ; // Inherit stdin
344
- stdio[1 ].flags = static_cast <uv_stdio_flags>(UV_CREATE_PIPE | UV_WRITABLE_PIPE);
345
- stdio[1 ].data .stream = (uv_stream_t *)&handle->stdoutPipe ;
346
- stdio[2 ].flags = static_cast <uv_stdio_flags>(UV_CREATE_PIPE | UV_WRITABLE_PIPE);
347
- stdio[2 ].data .stream = (uv_stream_t *)&handle->stderrPipe ;
357
+ stdio[0 ].flags = UV_IGNORE;
358
+ if (stdioKind == kStdioKindNone )
359
+ {
360
+ stdio[1 ].flags = UV_IGNORE;
361
+ stdio[2 ].flags = UV_IGNORE;
362
+ }
363
+ else if (stdioKind == kStdioKindInherit )
364
+ {
365
+ stdio[1 ].flags = UV_INHERIT_FD;
366
+ stdio[1 ].data .fd = fileno (stdout);
367
+ stdio[2 ].flags = UV_INHERIT_FD;
368
+ stdio[2 ].data .fd = fileno (stderr);
369
+ }
370
+ else if (stdioKind == kStdioKindDefault || stdioKind.empty ())
371
+ {
372
+ stdio[1 ].flags = static_cast <uv_stdio_flags>(UV_CREATE_PIPE | UV_WRITABLE_PIPE);
373
+ stdio[1 ].data .stream = (uv_stream_t *)&handle->stdoutPipe ;
374
+ stdio[2 ].flags = static_cast <uv_stdio_flags>(UV_CREATE_PIPE | UV_WRITABLE_PIPE);
375
+ stdio[2 ].data .stream = (uv_stream_t *)&handle->stderrPipe ;
376
+ }
377
+ else
378
+ {
379
+ luaL_error (L, " Invalid stdio kind: %s" , stdioKind.c_str ());
380
+ return 0 ;
381
+ }
348
382
options.stdio = stdio;
349
383
350
384
handle->process .data = handle.get ();
0 commit comments