From owner-ntemacs-users@june  Mon Sep 23 08:16:46 1996
X-VM-v5-Data: ([nil nil nil nil nil nil nil nil nil]
	[nil "Mon" "23" "September" "1996" "10:26:28" "-0400" "Kenneth L. Degrant, II" "kdegrant@earthlink.net" nil "28" "19.34 and Shell" "^From:" nil nil "9" nil nil nil nil]
	nil)
Received: from joker.cs.washington.edu (joker.cs.washington.edu [128.95.1.42]) by june.cs.washington.edu (8.7.5/7.2ju) with SMTP id IAA26377 for <voelker@june.cs.washington.edu>; Mon, 23 Sep 1996 08:16:46 -0700
Received: from june.cs.washington.edu (june.cs.washington.edu [128.95.1.4]) by joker.cs.washington.edu (8.6.12/7.2ws+) with ESMTP id IAA23335 for <voelker@joker.cs.washington.edu>; Mon, 23 Sep 1996 08:16:45 -0700
Received: from hungary.it.earthlink.net (hungary-c.it.earthlink.net [204.119.177.64]) by june.cs.washington.edu (8.7.5/7.2ju) with ESMTP id HAA24655 for <ntemacs-users@cs.washington.edu>; Mon, 23 Sep 1996 07:23:20 -0700
Received: from a12051.dracon.harris.com (a12051.nss.harris.com [151.114.22.138]) by hungary.it.earthlink.net (8.7.5/8.7.3) with SMTP id HAA13407 for <ntemacs-users@cs.washington.edu>; Mon, 23 Sep 1996 07:23:15 -0700 (PDT)
Message-ID: <32469E14.2D4@earthlink.net>
Organization: Harris Corporation
X-Mailer: Mozilla 2.01 (Win95; I)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
From: "Kenneth L. Degrant II" <kdegrant@earthlink.net>
To: ntemacs-users@cs.washington.edu
Subject: 19.34 and Shell
Date: Mon, 23 Sep 1996 10:26:28 -0400

When I went from 19.33 to 19.34, I started having problems
spawning grep, or compile, with

"start-process-shell-command"

I gave it the name of a bat file which prints the args, and I got
argv0 = mybat.bat one two three four......
argv1 = 
argv.....

What am I doing wrong, or what is wrong.  For now I am going to go
back to 19.33.

Kenneth


-- 
------------------------------------------------------------------------------
Kenneth L. DeGrant II                          E-Mail:  
kdegrant@earthlink.net
Software Engineer                                       
kdegrant@harris.com
Harris Corporation                             Phone:   (910) 856-5445
Greensboro Operations                          Fax:     (910) 852-1820
3708 Alliance Drive                       
Greensboro, North Carolina  27407          
http://home.earthlink.net/~kdegrant
------------------------------------------------------------------------------

From andrewi@harlequin.co.uk  Fri Jul 26 07:56:59 1996
X-VM-v5-Data: ([nil nil nil nil nil nil nil nil nil]
	[nil "Fri" "26" "July" "1996" "15:55:29" "+0100" "Andrew Innes" "andrewi@harlequin.co.uk" nil "96" "Re: [preilly@rokchr.shr.dec.com: VC checkin failure]" "^From:" nil nil "7" nil nil nil nil]
	nil)
Received: from holly.cam.harlequin.co.uk (holly.cam.harlequin.co.uk [193.128.4.58]) by june.cs.washington.edu (8.7.5/7.2ju) with SMTP id HAA08360 for <voelker@cs.washington.edu>; Fri, 26 Jul 1996 07:56:57 -0700
Received: from propos.long.harlequin.co.uk by holly.cam.harlequin.co.uk; Fri, 26 Jul 1996 15:56:54 +0100
Received: from woozle.long.harlequin.co.uk (woozle [193.128.93.77]) by propos.long.harlequin.co.uk (8.6.12/8.6.12) with SMTP id PAA23293; Fri, 26 Jul 1996 15:55:29 +0100
Message-Id: <199607261455.PAA23293@propos.long.harlequin.co.uk>
In-Reply-To: <199607260454.VAA39246@joker.cs.washington.edu> 	(voelker@cs.washington.edu)
From: Andrew Innes <andrewi@harlequin.co.uk>
To: voelker@cs.washington.edu
Cc: rms@gnu.ai.mit.edu
Subject: Re: [preilly@rokchr.shr.dec.com: VC checkin failure]
Date: Fri, 26 Jul 1996 15:55:29 +0100

On Thu, 25 Jul 1996 21:02:27 -0700 (PDT), voelker@cs.washington.edu (Geoff Voelker) said:
>The short story then is that sometimes we want arguments quoted (when
>they truly are arguments with whitespace in them) and at other times
>we don't (when they are entire commands and arguments concatenated
>together into one string but separated by whitespace), and it is not
>obvious how to distinguish these cases inside Emacs.  If arguments to
>commands were always broken up into argv components by the time it
>reaches child_setup (e.g., the grep command, even though an argument
>to the shell, would be broken up into its components, too), then I
>think we could safely set win32-quote-process-args to t by default.
>But this seems impossible to ensure.

Thinking about it from the Unix perspective, the argv array given to
child_setup is already correct because the shell expects a single arg
containing the entire command following -c, which it will interpret as
if it was typed in at the command line and so construct the proper argv
array for grep.

If the standard shell on NT had a sufficiently powerful quoting and
escaping syntax, as the Unix shells do, then this would work on NT as
well even though we have to flatten the array into a single string - any
quoting in the original command arg could be passed through to the shell
by proper escaping.

As it is now, for shell commands the correct behaviour is to have
win32-quote-process-args turned off, because cmd.exe will interpret the
rest of its command line (after consuming things it believes are command
switches for it) as a command line typed by the user.  (When using a
different shell, though, the rule might well be different.)

When starting other processes directly, usually the right thing is to
have win32-quote-process-args enabled - we have to assume that the
caller has constructed the argv array as they intend the subprocess to
see it (if they haven't, then things would fail on Unix), so in this
case, Emacs should quote the args as necessary to ensure the subprocess
reconstructs the args as intended.  In general this isn't possible
because there is no standard or universally used convention for parsing
the command line, but most of the time putting double quotes around an
arg if it contains spaces is correct.

It would have been nice if all places in lisp code which run commmands
via a shell process used shell-command or shell-command-on-region (so we
could set win32-quote-process-args there), but a quick perusal of the
lisp dir shows lots of examples where code does

   (call-process shell-file-name ... "-c" args)

or similar things.  It is too much to expect all packages to go through
the shell-command interface, so we need to deal with this at a lower
level than shell-command.

[One possibility: If we could insist that people use a specific shell on
NT (not cmd.exe), then we could solve the shell command problem that
way.  Or more likely, we would provide a subprocess "helper" application
that NT Emacs always used to invoke whatever program is really intended.
This ends up using extra process resources unnecessarily in many cases.]


>Alternatively, we could have the NT specific code check to see if the
>command it is spawning is the shell (and the second argument is the
>equivalent of "/c"), and have that code automatically break up into
>components the command to be executed in the shell (assuming that
>words that should go together are already quoted).  Otherwise, we
>would quote any arguments with whitespace in them (that are not
>already quoted).  Andrew, can you think of a case where this wouldn't
>work very well?

No - I think something along these lines will be necessary (and this is
the best suggestion I've seen so far).

However, it occurs to me that we should really provide a way for the
user to specify what kind of quoting behaviour is required in each case.
We know that the correct quoting really depends on which shell program
is being used (and not just shells - some individual programs may
require special handling as well).

I suggest adding a hook or handler mechansim of some sort (to both
start-process and call-process) to allow lisp code to modify the arg
list before it is passed to child_setup.  That way, the lisp code could
implement proper quoting, or splitting of args etc, based on the program
name or whatever criteria was considered appropriate.

This would even allow working with packages that directly call "sh",
"rm", or other Unix-specific programs - if a user wanted to, they could
intercept invocations of specific programs and invoke an appropriate
substitute instead.  In the case of call-process, they might even want
to implement the functionality entirely in lisp (eg. you could imagine
ls-lisp working this way), but this is probably going too far.

Then child_setup et al would not need to worry about this issue -
win32-quote-process-args would go, and sys_spawnve would always simply
concatenate the args together separated by spaces.

Does this sound like a reasonable solution?

AndrewI

From andrewi@harlequin.co.uk  Fri Jul 26 08:52:39 1996
X-VM-v5-Data: ([nil nil nil nil nil nil nil nil nil]
	[nil "Fri" "26" "July" "1996" "16:52:29" "+0100" "Andrew Innes" "andrewi@harlequin.co.uk" nil "27" "Re: [preilly@rokchr.shr.dec.com: VC checkin failure]" "^From:" nil nil "7" nil nil nil nil]
	nil)
Received: from holly.cam.harlequin.co.uk (holly.cam.harlequin.co.uk [193.128.4.58]) by june.cs.washington.edu (8.7.5/7.2ju) with SMTP id IAA13939 for <voelker@cs.washington.edu>; Fri, 26 Jul 1996 08:52:37 -0700
Received: from propos.long.harlequin.co.uk by holly.cam.harlequin.co.uk; Fri, 26 Jul 1996 16:52:34 +0100
Received: from woozle.long.harlequin.co.uk (woozle [193.128.93.77]) by propos.long.harlequin.co.uk (8.6.12/8.6.12) with SMTP id QAA26541; Fri, 26 Jul 1996 16:52:29 +0100
Message-Id: <199607261552.QAA26541@propos.long.harlequin.co.uk>
In-Reply-To: <199607261455.PAA23293@propos.long.harlequin.co.uk> (andrewi)
From: Andrew Innes <andrewi@harlequin.co.uk>
To: andrewi@harlequin.co.uk
Cc: voelker@cs.washington.edu, rms@gnu.ai.mit.edu
Subject: Re: [preilly@rokchr.shr.dec.com: VC checkin failure]
Date: Fri, 26 Jul 1996 16:52:29 +0100

On Fri, 26 Jul 1996 15:55:29 +0100, Andrew Innes <andrewi> said:
  [ .. ]
>However, it occurs to me that we should really provide a way for the
>user to specify what kind of quoting behaviour is required in each case.
>We know that the correct quoting really depends on which shell program
>is being used (and not just shells - some individual programs may
>require special handling as well).
>
>I suggest adding a hook or handler mechansim of some sort (to both
>start-process and call-process) to allow lisp code to modify the arg
>list before it is passed to child_setup.  That way, the lisp code could
>implement proper quoting, or splitting of args etc, based on the program
>name or whatever criteria was considered appropriate.

An obvious way of adding a "hook" mechansim would be to introduce a
variable `process-name-arg-handler-alist' (say), which relates regexps
(matching on program name) to handler functions that would return the
actual argument list (including the program name) to be used.

If the handler was `t' then "standard" quoting of args with spaces would
be performed; `nil' would mean use the original arg list directly.

There is no reason this mechansim (if accepted) shouldn't be provided
for all platforms, although it is most useful for Windows (and DOS, and
maybe VMS).

AndrewI

From eliz@is.elta.co.il  Tue Nov  4 02:38:29 1997
X-VM-v5-Data: ([nil nil nil nil nil nil nil nil nil]
	[nil "Tue" " 4" "November" "1997" "12:35:41" "+0200" "Eli Zaretskii" "eliz@is.elta.co.il" nil "63" "Re: win32-quote-process-args" "^From:" nil nil "11" nil nil nil nil]
	nil)
Received: from is.elta.co.il (is.elta.co.il [199.203.121.2]) by june.cs.washington.edu (8.8.7+CS/7.2ju) with SMTP id CAA06714; Tue, 4 Nov 1997 02:38:27 -0800
Received: by is.elta.co.il (SMI-8.6/SMI-SVR4) 	id MAA19348; Tue, 4 Nov 1997 12:35:42 +0200
X-Sender: eliz@is
In-Reply-To: <199711032109.OAA04908@airedale.ihsyp>
Message-ID: <Pine.SUN.3.91.971104123427.19282J-100000@is>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
From: Eli Zaretskii <eliz@is.elta.co.il>
To: kevin.rodgers@ihs.com
cc: GNU Emacs information <help-gnu-emacs@prep.ai.mit.edu>,         NT Emacs mailing list <ntemacs-users@cs.washington.edu>,         Geoff Voelker <voelker@cs.washington.edu>,         Andrew Innes <andrewi@harlequin.co.uk>
Subject: Re: win32-quote-process-args
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.

From eliz@is.elta.co.il  Tue Nov  4 02:43:10 1997
X-VM-v5-Data: ([nil nil nil nil nil nil nil nil nil]
	[nil "Tue" " 4" "November" "1997" "12:36:19" "+0200" "Eli Zaretskii" "eliz@is.elta.co.il" nil "28" "Re: Ediff cannot handle C-m in output of diff" "^From:" nil nil "11" nil nil nil nil]
	nil)
Received: from is.elta.co.il (is.elta.co.il [199.203.121.2]) by june.cs.washington.edu (8.8.7+CS/7.2ju) with SMTP id CAA06736; Tue, 4 Nov 1997 02:39:41 -0800
Received: by is.elta.co.il (SMI-8.6/SMI-SVR4) 	id MAA19355; Tue, 4 Nov 1997 12:36:20 +0200
X-Sender: eliz@is
In-Reply-To: <199711032106.WAA10322@aciinfo1.mchp.siemens.de>
Message-ID: <Pine.SUN.3.91.971104123557.19282K-100000@is>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
From: Eli Zaretskii <eliz@is.elta.co.il>
To: Thorbjoern Hansen <thorbjoern.hansen@mchp.siemens.de>
cc: bug-gnu-emacs@prep.ai.mit.edu, Michael Kifer <kifer@cs.sunysb.edu>,         voelker@cs.washington.edu, ntemacs-users@cs.washington.edu
Subject: Re: Ediff cannot handle C-m in output of diff
Date: Tue, 4 Nov 1997 12:36:19 +0200 (IST)


On Mon, 3 Nov 1997, Thorbjoern Hansen wrote:

> I have trouble using Ediff under Windows NT together with a version of
> 'diff' for Windows NT that insists on emitting "\C-m\C-j" instead of
> only "\C-j". Ediff reports:
> 
>   Errors in diff output. Diff output is in #<buffer *ediff-diff*>
>   
> and that buffer will contain lines like
> 
>   3c3^M
>   20a21^M
>   62a64,65^M
> 
> If I change the setting of the two variables
> ediff-diff-ok-lines-regexp and ediff-match-diff-line in ediff-diff.el
> to include "\C-m?" before "$", Ediff will work correctly.

IMHO, this is not a problem with Ediff, and therefore it's not Ediff
which should correct it.  These C-m (aka CR, the Carriage Return)
characters should have been stripped by Emacs when it reads diff's
output.  This is how it works in the MS-DOS version of Emacs, although
DOS versions of `diff' also write the CR characters at the end of each
line.

Please also note that Emacs 20 has a mechanism whereby the EOL
conversion (CRLF <-> NL) on input and output happens automatically.

