unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#20744: shell-quote-argument in Emacs 24.5 and Emacs 25 on Windows cannot figure out path correctly
@ 2015-06-05 16:33 Da Zhang
  2015-06-05 20:13 ` Eli Zaretskii
  2016-08-10  0:51 ` npostavs
  0 siblings, 2 replies; 17+ messages in thread
From: Da Zhang @ 2015-06-05 16:33 UTC (permalink / raw)
  To: 20744, eliz

[-- Attachment #1: Type: text/html, Size: 16841 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* bug#20744: shell-quote-argument in Emacs 24.5 and Emacs 25 on Windows cannot figure out path correctly
  2015-06-05 16:33 bug#20744: shell-quote-argument in Emacs 24.5 and Emacs 25 on Windows cannot figure out path correctly Da Zhang
@ 2015-06-05 20:13 ` Eli Zaretskii
  2015-06-05 20:50   ` Da Zhang
                     ` (2 more replies)
  2016-08-10  0:51 ` npostavs
  1 sibling, 3 replies; 17+ messages in thread
From: Eli Zaretskii @ 2015-06-05 20:13 UTC (permalink / raw)
  To: Da Zhang; +Cc: 20744

> Date: Fri, 05 Jun 2015 12:33:59 -0400
> From: Da Zhang <zhangda82@gmail.com>
> 
> I use python mode (python.el) for some python programming. When I invoke
> the command python-shell-send-buffer, my Emacs always reports "Searching
> for program: no such file or directory,
> c\:/Anaconda3/Scripts/ipython.exe".
> 
> I traced down the cause of this problem, and found the following lines
> in python.el:
> (defun python-shell-parse-command () ;FIXME: why name it "parse"?
> "Calculate the string used to execute the inferior Python process."
> ;; FIXME: process-environment doesn't seem to be used anywhere within
> ;; this let.
> (let ((process-environment (python-shell-calculate-process-environment))
> (exec-path (python-shell-calculate-exec-path)))
> (format "%s %s"
> ;; FIXME: Why executable-find?
> (shell-quote-argument (executable-find python-shell-interpreter))
> python-shell-interpreter-args)))
> 
> The function call 
> (shell-quote-argument (executable-find python-shell-interpreter))
> changed the path of my python interpreter from
> "c:/Anaconda3/Scripts/ipython.exe"
> to
> "c\\:/Anaconda3/Scripts/ipython.exe".
> 
> I worked around this problem by replacing the function call
> (shell-quote-argument (executable-find python-shell-interpreter))
> with
> (executable-find python-shell-interpreter) ;; edited by DZ on
> 2015/06/05: (shell-quote-argument) caused the problem of
> "c\\:/Anaconda3/Scripts/ipython.exe"
> 
> To further analyze the problem, I found the function
> shell-quote-argument defined in subr.el does not deal with the case when
> bash from cygwin is used.

For the record, this is bug #20237.

> I added the following lines in the cond statement, to solve the problem.
> ((and (eq system-type 'windows-nt) (if (string-match ".*cygwin.*"
> (w32-shell-name)) t nil)) ;; DZ's edit on 6/5/2015
> (if (equal argument "")
> "''"
> ;; Quote everything except POSIX filename characters.
> ;; This should be safe enough even for really weird shells.
> (replace-regexp-in-string
> "\n" "'\n'"
> (replace-regexp-in-string "[^-0-9a-zA-Z_./\n:]" "\\\\\\&" argument))))

I'm sorry, but I don't see how we can accept such a change: it means
that when the Cygwin Bash is used as the shell, the ':' character will
not be quoted, which I think could cause trouble in some cases.

Maybe some Bash expert could chime in and tell whether problems are
possible with Bash in this case.

Is there any way you could avoid using the Cygwin Bash as the shell
when running the native Windows build of Emacs?  That would make the
problem go away without any need for changes.





^ permalink raw reply	[flat|nested] 17+ messages in thread

* bug#20744: shell-quote-argument in Emacs 24.5 and Emacs 25 on Windows cannot figure out path correctly
  2015-06-05 20:13 ` Eli Zaretskii
@ 2015-06-05 20:50   ` Da Zhang
  2015-06-05 21:05   ` Da Zhang
  2015-06-07 18:01   ` Glenn Morris
  2 siblings, 0 replies; 17+ messages in thread
From: Da Zhang @ 2015-06-05 20:50 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 20744

[-- Attachment #1: Type: text/html, Size: 4910 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* bug#20744: shell-quote-argument in Emacs 24.5 and Emacs 25 on Windows cannot figure out path correctly
  2015-06-05 20:13 ` Eli Zaretskii
  2015-06-05 20:50   ` Da Zhang
@ 2015-06-05 21:05   ` Da Zhang
  2015-06-07 18:01   ` Glenn Morris
  2 siblings, 0 replies; 17+ messages in thread
From: Da Zhang @ 2015-06-05 21:05 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 20744

[-- Attachment #1: Type: text/html, Size: 3613 bytes --]

[-- Attachment #2: gaefedad.png --]
[-- Type: image/png, Size: 18480 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* bug#20744: shell-quote-argument in Emacs 24.5 and Emacs 25 on Windows cannot figure out path correctly
  2015-06-05 20:13 ` Eli Zaretskii
  2015-06-05 20:50   ` Da Zhang
  2015-06-05 21:05   ` Da Zhang
@ 2015-06-07 18:01   ` Glenn Morris
  2015-06-07 19:11     ` Eli Zaretskii
  2 siblings, 1 reply; 17+ messages in thread
From: Glenn Morris @ 2015-06-07 18:01 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 20744, Da Zhang

Eli Zaretskii wrote:

> I'm sorry, but I don't see how we can accept such a change: it means
> that when the Cygwin Bash is used as the shell, the ':' character will
> not be quoted, which I think could cause trouble in some cases.
>
> Maybe some Bash expert could chime in and tell whether problems are
> possible with Bash in this case.

Not an expert (and didn't read the rest of the report), but I can't
think of a reason why ':' would need quoting in Bash (unlike eg ';' or '&').
What kind of thing are you thinking of?





^ permalink raw reply	[flat|nested] 17+ messages in thread

* bug#20744: shell-quote-argument in Emacs 24.5 and Emacs 25 on Windows cannot figure out path correctly
  2015-06-07 18:01   ` Glenn Morris
@ 2015-06-07 19:11     ` Eli Zaretskii
  2015-06-08  0:07       ` Glenn Morris
  0 siblings, 1 reply; 17+ messages in thread
From: Eli Zaretskii @ 2015-06-07 19:11 UTC (permalink / raw)
  To: Glenn Morris; +Cc: 20744, zhangda82

> From: Glenn Morris <rgm@gnu.org>
> Cc: Da Zhang <zhangda82@gmail.com>,  20744@debbugs.gnu.org
> Date: Sun, 07 Jun 2015 14:01:31 -0400
> 
> Eli Zaretskii wrote:
> 
> > I'm sorry, but I don't see how we can accept such a change: it means
> > that when the Cygwin Bash is used as the shell, the ':' character will
> > not be quoted, which I think could cause trouble in some cases.
> >
> > Maybe some Bash expert could chime in and tell whether problems are
> > possible with Bash in this case.
> 
> Not an expert (and didn't read the rest of the report), but I can't
> think of a reason why ':' would need quoting in Bash (unlike eg ';' or '&').
> What kind of thing are you thinking of?

PATH-style lists, maybe.

Anyway, if we think ':' doesn't need to be quoted, how about removing
it from the Posix branch of shell-quote-argument?  Then we won't need
ugly hacks that try to detect Cygwin Bash used from a native Windows
Emacs.





^ permalink raw reply	[flat|nested] 17+ messages in thread

* bug#20744: shell-quote-argument in Emacs 24.5 and Emacs 25 on Windows cannot figure out path correctly
  2015-06-07 19:11     ` Eli Zaretskii
@ 2015-06-08  0:07       ` Glenn Morris
  2015-06-08  0:24         ` Glenn Morris
  2015-06-08 14:03         ` Stefan Monnier
  0 siblings, 2 replies; 17+ messages in thread
From: Glenn Morris @ 2015-06-08  0:07 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 20744, zhangda82

Eli Zaretskii wrote:

> Anyway, if we think ':' doesn't need to be quoted, how about removing
> it from the Posix branch of shell-quote-argument?

The comment there says "This should be safe enough even for really weird
shells." That's a much broader question than just Bash! :)

But I thought of an example that affects Bash:

scp localfile remotehost:

If "localfile" contains ":", things will get confused.
So it's probably best to leave it as-is.





^ permalink raw reply	[flat|nested] 17+ messages in thread

* bug#20744: shell-quote-argument in Emacs 24.5 and Emacs 25 on Windows cannot figure out path correctly
  2015-06-08  0:07       ` Glenn Morris
@ 2015-06-08  0:24         ` Glenn Morris
  2015-06-08  0:47           ` Glenn Morris
  2015-06-08 14:03         ` Stefan Monnier
  1 sibling, 1 reply; 17+ messages in thread
From: Glenn Morris @ 2015-06-08  0:24 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 20744, zhangda82

Glenn Morris wrote:

> scp localfile remotehost:

Well, that's not a shell issue, though. It's an scp issue.
So it depends exactly what shell-quote-argument is for...






^ permalink raw reply	[flat|nested] 17+ messages in thread

* bug#20744: shell-quote-argument in Emacs 24.5 and Emacs 25 on Windows cannot figure out path correctly
  2015-06-08  0:24         ` Glenn Morris
@ 2015-06-08  0:47           ` Glenn Morris
  2015-06-08  2:43             ` Eli Zaretskii
  0 siblings, 1 reply; 17+ messages in thread
From: Glenn Morris @ 2015-06-08  0:47 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 20744, zhangda82


I think the actual answer for Bash is the "metacharacters" list in the
Bash manual, plus the "!" character (for history), as per:

http://www.gnu.org/software/bash/manual/html_node/Quoting.html

That doesn't include ":", but then there's those "really weird shells",
whatever they may be...






^ permalink raw reply	[flat|nested] 17+ messages in thread

* bug#20744: shell-quote-argument in Emacs 24.5 and Emacs 25 on Windows cannot figure out path correctly
  2015-06-08  0:47           ` Glenn Morris
@ 2015-06-08  2:43             ` Eli Zaretskii
  2015-06-08  7:43               ` Michael Albinus
  0 siblings, 1 reply; 17+ messages in thread
From: Eli Zaretskii @ 2015-06-08  2:43 UTC (permalink / raw)
  To: Glenn Morris; +Cc: 20744, zhangda82

> From: Glenn Morris <rgm@gnu.org>
> Cc: 20744@debbugs.gnu.org,  zhangda82@gmail.com
> Date: Sun, 07 Jun 2015 20:47:09 -0400
> 
> 
> I think the actual answer for Bash is the "metacharacters" list in the
> Bash manual, plus the "!" character (for history), as per:
> 
> http://www.gnu.org/software/bash/manual/html_node/Quoting.html
> 
> That doesn't include ":", but then there's those "really weird shells",
> whatever they may be...

Perhaps we could have a branch for Bash only.





^ permalink raw reply	[flat|nested] 17+ messages in thread

* bug#20744: shell-quote-argument in Emacs 24.5 and Emacs 25 on Windows cannot figure out path correctly
  2015-06-08  2:43             ` Eli Zaretskii
@ 2015-06-08  7:43               ` Michael Albinus
  2015-06-08 14:31                 ` Eli Zaretskii
  0 siblings, 1 reply; 17+ messages in thread
From: Michael Albinus @ 2015-06-08  7:43 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 20744, zhangda82

Eli Zaretskii <eliz@gnu.org> writes:

>> That doesn't include ":", but then there's those "really weird shells",
>> whatever they may be...
>
> Perhaps we could have a branch for Bash only.

Tramp would happily join that branch, for "really weird shells on a
remote host".





^ permalink raw reply	[flat|nested] 17+ messages in thread

* bug#20744: shell-quote-argument in Emacs 24.5 and Emacs 25 on Windows cannot figure out path correctly
  2015-06-08  0:07       ` Glenn Morris
  2015-06-08  0:24         ` Glenn Morris
@ 2015-06-08 14:03         ` Stefan Monnier
  1 sibling, 0 replies; 17+ messages in thread
From: Stefan Monnier @ 2015-06-08 14:03 UTC (permalink / raw)
  To: Glenn Morris; +Cc: 20744, zhangda82

>> Anyway, if we think ':' doesn't need to be quoted, how about removing
>> it from the Posix branch of shell-quote-argument?
> The comment there says "This should be safe enough even for really weird
> shells." That's a much broader question than just Bash! :)

Let's stop escaping the : and if/when someone comes up with a very weird
shell where this is a problem, we'll see what can be done.


        Stefan





^ permalink raw reply	[flat|nested] 17+ messages in thread

* bug#20744: shell-quote-argument in Emacs 24.5 and Emacs 25 on Windows cannot figure out path correctly
  2015-06-08  7:43               ` Michael Albinus
@ 2015-06-08 14:31                 ` Eli Zaretskii
  2015-06-08 15:14                   ` Michael Albinus
  0 siblings, 1 reply; 17+ messages in thread
From: Eli Zaretskii @ 2015-06-08 14:31 UTC (permalink / raw)
  To: Michael Albinus; +Cc: 20744, zhangda82

> From: Michael Albinus <michael.albinus@gmx.de>
> Cc: Glenn Morris <rgm@gnu.org>,  20744@debbugs.gnu.org,  zhangda82@gmail.com
> Date: Mon, 08 Jun 2015 09:43:32 +0200
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> >> That doesn't include ":", but then there's those "really weird shells",
> >> whatever they may be...
> >
> > Perhaps we could have a branch for Bash only.
> 
> Tramp would happily join that branch, for "really weird shells on a
> remote host".

Meaning you are for such a change, or against it?  (Sorry, it wasn't
clear from what you said.)





^ permalink raw reply	[flat|nested] 17+ messages in thread

* bug#20744: shell-quote-argument in Emacs 24.5 and Emacs 25 on Windows cannot figure out path correctly
  2015-06-08 14:31                 ` Eli Zaretskii
@ 2015-06-08 15:14                   ` Michael Albinus
  2015-06-08 16:22                     ` Eli Zaretskii
  0 siblings, 1 reply; 17+ messages in thread
From: Michael Albinus @ 2015-06-08 15:14 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 20744, zhangda82

Eli Zaretskii <eliz@gnu.org> writes:

>> >> That doesn't include ":", but then there's those "really weird shells",
>> >> whatever they may be...
>> >
>> > Perhaps we could have a branch for Bash only.
>> 
>> Tramp would happily join that branch, for "really weird shells on a
>> remote host".
>
> Meaning you are for such a change, or against it?  (Sorry, it wasn't
> clear from what you said.)

Bash is always a pain to handle, there are exceptions in Tramp's code
for that. But having a branch for this is not realistic for Tramp,
because Tramp doesn't distinguish remote shells, it only expects that
they speak a bourne-shell dialect.

My message was rather a sigh than a request.

Best regards, Michael.





^ permalink raw reply	[flat|nested] 17+ messages in thread

* bug#20744: shell-quote-argument in Emacs 24.5 and Emacs 25 on Windows cannot figure out path correctly
  2015-06-08 15:14                   ` Michael Albinus
@ 2015-06-08 16:22                     ` Eli Zaretskii
  2015-06-08 16:34                       ` Michael Albinus
  0 siblings, 1 reply; 17+ messages in thread
From: Eli Zaretskii @ 2015-06-08 16:22 UTC (permalink / raw)
  To: Michael Albinus; +Cc: 20744, zhangda82

> From: Michael Albinus <michael.albinus@gmx.de>
> Cc: rgm@gnu.org,  20744@debbugs.gnu.org,  zhangda82@gmail.com
> Date: Mon, 08 Jun 2015 17:14:33 +0200
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> >> >> That doesn't include ":", but then there's those "really weird shells",
> >> >> whatever they may be...
> >> >
> >> > Perhaps we could have a branch for Bash only.
> >> 
> >> Tramp would happily join that branch, for "really weird shells on a
> >> remote host".
> >
> > Meaning you are for such a change, or against it?  (Sorry, it wasn't
> > clear from what you said.)
> 
> Bash is always a pain to handle, there are exceptions in Tramp's code
> for that. But having a branch for this is not realistic for Tramp,
> because Tramp doesn't distinguish remote shells, it only expects that
> they speak a bourne-shell dialect.
> 
> My message was rather a sigh than a request.

How about Stefan's suggestion to stop quoting the colon and see if
anybody hollers?  Are you okay with that, or will you holler?





^ permalink raw reply	[flat|nested] 17+ messages in thread

* bug#20744: shell-quote-argument in Emacs 24.5 and Emacs 25 on Windows cannot figure out path correctly
  2015-06-08 16:22                     ` Eli Zaretskii
@ 2015-06-08 16:34                       ` Michael Albinus
  0 siblings, 0 replies; 17+ messages in thread
From: Michael Albinus @ 2015-06-08 16:34 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 20744, zhangda82

Eli Zaretskii <eliz@gnu.org> writes:

> How about Stefan's suggestion to stop quoting the colon and see if
> anybody hollers?  Are you okay with that, or will you holler?

That would be OK. We'll hear it, when Tramp users start to holler.

Best regards, Michael.





^ permalink raw reply	[flat|nested] 17+ messages in thread

* bug#20744: shell-quote-argument in Emacs 24.5 and Emacs 25 on Windows cannot figure out path correctly
  2015-06-05 16:33 bug#20744: shell-quote-argument in Emacs 24.5 and Emacs 25 on Windows cannot figure out path correctly Da Zhang
  2015-06-05 20:13 ` Eli Zaretskii
@ 2016-08-10  0:51 ` npostavs
  1 sibling, 0 replies; 17+ messages in thread
From: npostavs @ 2016-08-10  0:51 UTC (permalink / raw)
  To: Da Zhang; +Cc: 20744

retitle 20744 python.el tries to undo shell quoting with split-string-and-unquote
tags 20744 confirmed
found 20744 25.1
quit

Da Zhang <zhangda82@gmail.com> writes:

> From: Da Zhang <zhangda82@gmail.com>
> To: bug-gnu-emacs@gnu.org
> Subject: 24.5; shell-quote-argument in Emacs 24.5 and Emacs 25 on Windows cannot figure out path correctly
> --text follows this line--
>
> Dear Emacs developers/maintainers,
>
> I am writing this email to report an issue that has been bothering me
> for a while.
>
> I use python mode (python.el) for some python programming. When I invoke
> the command python-shell-send-buffer, my Emacs always reports "Searching
> for program: no such file or directory,
> c\:/Anaconda3/Scripts/ipython.exe".
>
[...]
>
> The function call 
> (shell-quote-argument (executable-find python-shell-interpreter))
> changed the path of my python interpreter from
> "c:/Anaconda3/Scripts/ipython.exe"
> to
> "c\\:/Anaconda3/Scripts/ipython.exe".
>
> I worked around this problem by replacing the function call
> (shell-quote-argument (executable-find python-shell-interpreter))
> with
> (executable-find python-shell-interpreter) ;; edited by DZ on
> 2015/06/05: (shell-quote-argument) caused the problem of
> "c\\:/Anaconda3/Scripts/ipython.exe"
>
> To further analyze the problem, I found the function
> shell-quote-argument defined in subr.el does not deal with the case when
> bash from cygwin is used.
>
[...]

Actually, bash, regardless of being on cygwin or not, should have no
problem with an escaped ":".  The actual problem here is that python.el
is using shell-quote-argument but then not using a shell.  The result of
python-shell-calculate-command (formerly known as
python-shell-parse-command) gets passed to python-shell-make-comint as
the CMD argument:

(defun python-shell-make-comint (cmd proc-name &optional show internal)
  [...]
          (let* ((cmdlist (split-string-and-unquote cmd))
                 (buffer (apply #'make-comint-in-buffer proc-name proc-buffer-name
                                interpreter nil args))

make-comint-in-buffer uses start-file-process, i.e., no shell is called.
So python.el is trying to undo shell-quote-argument with
split-string-and-unquote, this is the bug.

To see this on any system, compare

    C-u M-x run-python RET 'python' -i

this fails, while

    C-u M-x run-python RET "python" -i

this succeeds (assuming you have python in exec-path).






^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2016-08-10  0:51 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-05 16:33 bug#20744: shell-quote-argument in Emacs 24.5 and Emacs 25 on Windows cannot figure out path correctly Da Zhang
2015-06-05 20:13 ` Eli Zaretskii
2015-06-05 20:50   ` Da Zhang
2015-06-05 21:05   ` Da Zhang
2015-06-07 18:01   ` Glenn Morris
2015-06-07 19:11     ` Eli Zaretskii
2015-06-08  0:07       ` Glenn Morris
2015-06-08  0:24         ` Glenn Morris
2015-06-08  0:47           ` Glenn Morris
2015-06-08  2:43             ` Eli Zaretskii
2015-06-08  7:43               ` Michael Albinus
2015-06-08 14:31                 ` Eli Zaretskii
2015-06-08 15:14                   ` Michael Albinus
2015-06-08 16:22                     ` Eli Zaretskii
2015-06-08 16:34                       ` Michael Albinus
2015-06-08 14:03         ` Stefan Monnier
2016-08-10  0:51 ` npostavs

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).