Subject: Re: win32-quote-process-args

From: Eli Zaretskii <[email-masked]>
Date: Tue, 4 Nov 1997 12:35:41 +0200 (IST)

I don't maintain the NT port, and I didn't write the code that handles
this, so please take the following with a grain of salt.  Goeff and 
Andrew will have a better insight.

On Mon, 3 Nov 1997, Kevin Rodgers wrote:

> Can someone explain the purpose and use of the win32-quote-process-args
> variable in GNU Emacs for Windows 95/NT?  I maintain a package
> (igrep.el) that generates shell commands with quoted arguments, and am
> trying to support those inexplicably popular platforms.  However, I
> don't even know what the doc string for that variable says.

See src/w32proc.c  It has some comments about this.

In a word, it's a mess.  While on Unix wildcards are expanded by the
shell, native W95/NT shells don't do that (I'm positive about W95, but
might be in error about NT).  Therefore, there are two possible
situations: either the user installed a port of Unixy shell (such as
Bash) or they use the stock shell.  In the first case, you don't need
to quote the arguments at all, since the caller (the one which is
responsible for invoking the subprocess, in this case igrep.el) should
have quoted whatever needs to be quoted for such a shell.

It's the second case that might let all hell break lose on you.  In
this case, the wildcards are expanded by the application's startup
code.  The problem is, every compiler/library have their own ways of
handling that, including how special characters are quoted.  Making it
all work correctly is a programmer's nightmare.

> For starters, who is responsible for setting it: the Windows 95/NT Emacs
> implementation itself, the user (to make sure it's compatible with
> his/her setting of shell-file-name), or the programmer who calls
> shell-command or shell-command-on-region or start-process-shell-command?
> According to the bash, ksh, MKS ksh, and tchs items under
> <URL:http://www.cs.washington.edu/homes/voelker/ntemacs.html#shell>,
> it's the user's responsibility to set it.

This is correct, IMHO.  The user who knows what kind of input their
`grep' expects, should set this variable, if they need it (but see
below).  The programmer (you) don't have any clue about these; the
code on w32proc.c tries to guess the correct quoting by looking at the
executable, but it might easily get it wrong.

In addition, if `igrep' gets the command line from the user, the best
bet is for the user to quote the command line like their `grep'
expects.  After all, that is what they would do if they had invoked
`grep' from the command line, right?

> Since I am generating
> a shell command with a quoted argument, it would make sense for me to
> temporarily disable this "feature".  But I don't understand why a user's
> choice of shell should interact with this variable's value.

I don't know anything about igrep, so I cannot answer this.  It seems
that if you quote the command line, it would be best to disable
Emacs's quoting.  But quoting has its pitfalls, and I cannot advise
without seeing the command line.  One problem that might haunt you is
that most applications that expand wildcards don't know about the
single quotes, only double quotes are supported.  Another problem
with stock Windows shells is that they will not strip quotes from the
arguments when they pass them to `grep', which will then disable the
globbing of wildcards by `grep's startup code.