From 4b6150b4b771c19750af76830a49ee32d7ab5c9c Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 13 Jul 2016 06:34:22 -0700 Subject: Implement sh -> cmd.exe translation hack. * winsup/cygwin/spawn.cc (spawnve): Rewrite /bin/sh -c cmd invocations to use cmd.exe /c cmd instead. --- winsup/cygwin/spawn.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc index 4e468d928..253f2fbd1 100644 --- a/winsup/cygwin/spawn.cc +++ b/winsup/cygwin/spawn.cc @@ -1104,6 +1104,21 @@ spawnve (int mode, const char *path, const char *const *argv, { static char *const empty_env[] = { NULL }; + /* Cygnal hack! If the path is "/bin/sh" and argv is of the three-element + form { "", "-c", "" } then let us rewrite argv to: + { "", "/c", "" } and invoke "". + This will automatically "port" many programs that use hard-coded /bin/sh + for command execution. For instance, we can use the Cygwin-packaged + gawk.exe binary over Cygnal; awk pipes will work using cmd.exe.*/ + + if (argv[0] && argv[1] && argv[2] && !argv[3] && + !strcmp(path, "/bin/sh") && !strcmp(argv[1], "-c")) + { + const char *argv_sub[3] = { get_cmd_exe_path(), "/c", argv[2] }; + return spawnve (mode, argv_sub[0], + const_cast(argv_sub), envp); + } + int ret; syscall_printf ("spawnve (%s, %s, %p)", path, argv[0], envp); -- cgit v1.2.3