From c89270cf0d7c7b3f9c99075211a8178aca932f38 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 30 Jun 2016 23:22:15 -0700 Subject: Dynamically determine whether shell is cmd.exe. * stream.c (shell, shell_arg): New variables. (sh): Use shell and shell_arg, rather than hard-coded "/bin/sh" and "-c". (stream_init): Initialize shell and shell_arg to POSIX values. On Cygwin, call getusershell, and if it reports cmd.exe, use that instead, and adjust shell_arg to "/c". This will happen if the Cygwin DLL being used is the Cygnal version. --- stream.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/stream.c b/stream.c index 5df416f8..8abff6cb 100644 --- a/stream.c +++ b/stream.c @@ -85,6 +85,8 @@ val stdio_stream_s; val socket_error_s; #endif +val shell, shell_arg; + void strm_base_init(struct strm_base *s) { static struct strm_base init = { indent_off, 60, 10, 0, 0 }; @@ -3855,7 +3857,7 @@ out: static val sh(val command) { - return run(lit("/bin/sh"), list(lit("-c"), command, nao)); + return run(shell, list(shell_arg, command, nao)); } #elif HAVE_WSPAWN static val run(val command, val args) @@ -4112,4 +4114,19 @@ void stream_init(void) record_adapter_ops.get_sock_peer = delegate_get_sock_peer; record_adapter_ops.set_sock_peer = delegate_set_sock_peer; #endif + + + shell = lit("/bin/sh"); + shell_arg = lit("-c"); + +#ifdef __CYGWIN__ + { + const char *sh = getusershell(); + if (sh && strstr(sh, "cmd.exe")) { + prot1(&shell); + shell = string_utf8(sh); + shell_arg = lit("/c"); + } + } +#endif } -- cgit v1.2.3