From: Noam Postavsky <npostavs@users.sourceforge.net>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 18745@debbugs.gnu.org
Subject: bug#18745: 24.3; MS Windows, `call-process-shell-command' fails on `shell-quote-argument'ed bat file with quoted args
Date: Tue, 21 Oct 2014 21:12:27 -0400 [thread overview]
Message-ID: <CAM-tV--_EQRWJ+YNXR34XQJLMsVA_fU8FZ+884b8q2eEWZRcPg@mail.gmail.com> (raw)
In-Reply-To: <CAM-tV-_FF7QkggL2+i1ebyCKD27bLHFQwA-TWfw89dLpgbUn=g@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1102 bytes --]
On Thu, Oct 16, 2014 at 5:30 PM, Noam Postavsky
<npostavs@users.sourceforge.net> wrote:
> On Thu, Oct 16, 2014 at 1:06 PM, Eli Zaretskii <eliz@gnu.org> wrote:
>> GNU Make overcomes this by detecting these cases, and invoking
>> CreateProcess in a special way (NULL as the first argument), see the
>> function process_begin there, around line 710 of sub_proc.c in the GNU
>> Make sources. If you can come up with a way to do the same in Emacs,
>> by some suitable patch to cmdproxy.c, such a patch will be welcome
>> (assuming either the patch is small, or you will agree to sign legal
>> papers necessary for submitting substantial patches to FSF projects).
>
> I'll take a look (btw I have already signed for Emacs).
Patching cmdproxy.c fixes the call-process-shell-command case:
(call-process-shell-command
"\"c:/path with space/foo-bar.bat\" \"x &y\"" nil '(t t) t)
To fix the call-process case:
(call-process
"c:/path with space/foo-bar.bat" nil '(t t) t "x &y")
required a patch to w32proc.c. This is my first patch to Emacs proper;
hopefully I got everything in the right format.
[-- Attachment #2: bat-quote.ChangeLog --]
[-- Type: application/octet-stream, Size: 323 bytes --]
2014-10-21 Noam Postavsky <npostavs@users.sourceforget.net>
Paper over MS Windows CreateProcess deficiencies (Bug#18745).
* nt/cmdproxy.c (batch_file_p): new function.
(spawn): if calling a quoted batch file pass NULL for progname.
* src/w32proc.c (create_child): if calling a quoted batch file
pass NULL for exe.
[-- Attachment #3: bat-quote.patch --]
[-- Type: application/octet-stream, Size: 2019 bytes --]
--- org/nt/cmdproxy.c Tue Oct 21 20:39:39 2014
+++ new/nt/cmdproxy.c Tue Oct 21 20:27:08 2014
@@ -220,6 +220,28 @@
return o - buf;
}
+/* Return TRUE if PROGNAME is a batch file */
+BOOL
+batch_file_p (const char *progname)
+{
+ const char *exts[] = {".bat", ".cmd"};
+ int n_exts = sizeof (exts) / sizeof (char *);
+ int i;
+
+ const char *ext = strrchr(progname, '.');
+
+ if (ext)
+ {
+ for (i = 0; i < n_exts; i++)
+ {
+ if (stricmp(ext, exts[i]) == 0)
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
/* Search for EXEC file in DIR. If EXEC does not have an extension,
DIR is searched for EXEC with the standard extensions appended. */
int
@@ -469,6 +491,13 @@
memset (&start, 0, sizeof (start));
start.cb = sizeof (start);
+
+ /* CreateProcess handles batch files as progname specially. This
+ special handling fails when both the batch file and arguments are
+ quoted. We pass NULL as progname to avoid the special
+ handling. */
+ if (progname != NULL && cmdline[0] == '"' && batch_file_p(progname))
+ progname = NULL;
if (CreateProcess (progname, cmdline, &sec_attrs, NULL, TRUE,
0, envblock, dir, &start, &child))
--- org/src/w32proc.c Tue Oct 21 20:39:43 2014
+++ new/src/w32proc.c Tue Oct 21 20:27:08 2014
@@ -1078,6 +1078,7 @@
DWORD flags;
char dir[ MAX_PATH ];
char *p;
+ const char *ext;
if (cp == NULL) emacs_abort ();
@@ -1115,6 +1116,15 @@
for (p = dir; *p; p = CharNextA (p))
if (*p == '/')
*p = '\\';
+
+ /* CreateProcess handles batch files as exe specially. This special
+ handling fails when both the batch file and arguments are
+ quoted. We pass NULL as exe to avoid the special handling. */
+ if (exe && cmdline[0] == '"' &&
+ (ext = strrchr(exe, '.')) &&
+ (xstrcasecmp (ext, ".bat") == 0
+ || xstrcasecmp (ext, ".cmd") == 0))
+ exe = NULL;
flags = (!NILP (Vw32_start_process_share_console)
? CREATE_NEW_PROCESS_GROUP
next prev parent reply other threads:[~2014-10-22 1:12 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-16 4:33 bug#18745: 24.3; MS Windows, `call-process-shell-command' fails on `shell-quote-argument'ed bat file with quoted args Noam Postavsky
2014-10-16 6:50 ` Eli Zaretskii
2014-10-16 13:47 ` Stefan Monnier
2014-10-16 13:57 ` Eli Zaretskii
2014-10-16 16:28 ` Noam Postavsky
2014-10-16 17:06 ` Eli Zaretskii
2014-10-16 21:30 ` Noam Postavsky
2014-10-22 1:12 ` Noam Postavsky [this message]
2014-10-22 17:12 ` Eli Zaretskii
2014-10-23 1:33 ` Noam Postavsky
2014-10-23 15:52 ` Eli Zaretskii
2014-10-25 9:16 ` Eli Zaretskii
2014-10-25 14:03 ` Noam Postavsky
2014-10-16 20:15 ` Stefan Monnier
2014-10-16 21:50 ` Noam Postavsky
2014-10-17 0:38 ` Stefan Monnier
2014-10-17 6:10 ` Eli Zaretskii
2014-10-17 6:05 ` Eli Zaretskii
2015-10-27 11:49 ` bug#18745: Juanma Barranquero
2015-10-27 19:14 ` bug#18745: Eli Zaretskii
2015-10-27 23:24 ` bug#18745: Juanma Barranquero
2015-10-28 16:01 ` bug#18745: Eli Zaretskii
2015-10-29 3:38 ` bug#18745: Juanma Barranquero
2015-10-29 16:17 ` bug#18745: Eli Zaretskii
2015-10-29 17:22 ` bug#18745: Juanma Barranquero
2015-10-30 14:25 ` bug#18745: Juanma Barranquero
2015-10-30 14:55 ` bug#18745: Eli Zaretskii
2015-10-30 17:09 ` bug#18745: Juanma Barranquero
2015-10-30 20:10 ` bug#18745: Eli Zaretskii
2015-10-31 23:20 ` bug#18745: Juanma Barranquero
2015-11-01 17:49 ` bug#18745: Eli Zaretskii
2015-11-01 18:29 ` bug#18745: Juanma Barranquero
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAM-tV--_EQRWJ+YNXR34XQJLMsVA_fU8FZ+884b8q2eEWZRcPg@mail.gmail.com \
--to=npostavs@users.sourceforge.net \
--cc=18745@debbugs.gnu.org \
--cc=eliz@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.