unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Ihor Radchenko <yantar92@posteo.net>
Cc: dmitry@gutov.dev, 71081@debbugs.gnu.org, matt@excalamus.com
Subject: bug#71081: 30.0.50; shell-command-on-region outputs boilerplate text on Windows
Date: Thu, 23 May 2024 17:14:19 +0300	[thread overview]
Message-ID: <867cfk4nus.fsf@gnu.org> (raw)
In-Reply-To: <875xv4y6er.fsf@localhost> (message from Ihor Radchenko on Thu, 23 May 2024 14:00:44 +0000)

> From: Ihor Radchenko <yantar92@posteo.net>
> Cc: dmitry@gutov.dev, 71081@debbugs.gnu.org, matt@excalamus.com
> Date: Thu, 23 May 2024 14:00:44 +0000
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> >> On Windows, it yields
> >> 
> >> "foo"
> >
> > Yes, because the Windows shell doesn't support command lines with
> > embedded newlines, so it ignores everything past the first newline.
> > (Actually, there are complicated tricks to do that, but I'll spare
> > you.)
> 
> Should it be documented in the docstring of `shell-command-to-string'?

We could, but IMO such tangential information belongs to the manual,
not to the doc string.  We should also somehow avoid the slippery
slope of describing all the differences between the Posix shells and
the Windows shell.  E.g., newlines are also not allowed in Windows
file names, but we don't mention that in doc strings of every function
that deals with file names.

> Currently, it only mentions `shell-quote-argument' and the current
> behaviour is not expected - there is nothing indicating that one should
> be careful about newlines (or any other characters passed to system
> shell).

Characters special to a shell always need special attention.  And
which characters are special to a given shell depends on the shell.
Emacs supports special characters for a couple of widely-used shells,
but not for all of them.

> > Instead, you should do this on Windows:
> >
> >   (shell-command-to-string "echo foo && echo bar")
> >
> > This is the documented method of invoking cmd.exe with multiple
> > commands.
> 
> Maybe. But `shell-command-on-region' does work with multi-line commands,

No, it works with multi-line _regions_, since the region is sent to
the shell command as input to process.

> Why would anyone assume that `shell-command-to-string' is
> passed as an argument to cmd.exe and not piped as input?

Because the doc string says so:

  Execute shell command COMMAND and return its output as a string.

"Execute COMMAND" means run it as "SHELL -c COMMAND", in any
reasonable interpretation.  Anything else is not the usual way of
running commands.

> more over, on Linux, different shells have different behaviors wrt
> input/command argument/script file).

Same on Windows.  Try PowerShell some day.  Does it mean we need to
document all of that in our documentation?





  reply	other threads:[~2024-05-23 14:14 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-20 18:34 bug#71081: 30.0.50; shell-command-on-region outputs boilerplate text on Windows Ihor Radchenko
2024-05-20 18:59 ` Eli Zaretskii
2024-05-21 20:18   ` Dmitry Gutov
2024-05-22  2:30     ` Eli Zaretskii
2024-05-22 11:45       ` Ihor Radchenko
2024-05-22 13:33         ` Eli Zaretskii
2024-05-22 14:26           ` Ihor Radchenko
2024-05-22 14:53             ` Eli Zaretskii
2024-05-23 12:06               ` Ihor Radchenko
2024-05-23 13:37                 ` Eli Zaretskii
2024-05-23 14:00                   ` Ihor Radchenko
2024-05-23 14:14                     ` Eli Zaretskii [this message]
2024-05-23 14:36                       ` Ihor Radchenko
2024-05-25 10:03                         ` Eli Zaretskii
2024-05-25 10:03                         ` Eli Zaretskii

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=867cfk4nus.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=71081@debbugs.gnu.org \
    --cc=dmitry@gutov.dev \
    --cc=matt@excalamus.com \
    --cc=yantar92@posteo.net \
    /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 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).