unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Prof Jayanth R Varma <jrvarma@gmail.com>
To: 36331@debbugs.gnu.org
Subject: bug#36331: 26.2; command run using dired-do-async-shell-command cannot take any input
Date: Sat, 22 Jun 2019 18:07:59 +0530	[thread overview]
Message-ID: <87mui9ztg8.fsf@JRVLAPTOP.i-did-not-set--mail-host-address--so-tickle-me> (raw)

dired-do-async-shell-command in dired-aux.el runs the command dired-shell-stuff-it which adds "&wait" to the command line. The source code explains the logic as follows:

                    ;; POSIX shells running a list of commands in the background
                    ;; (LIST = cmd_1 & [cmd_2 & ... cmd_i & ... cmd_N &])
                    ;; return once cmd_N ends, i.e., the shell does not
                    ;; wait for cmd_i to finish before executing cmd_i+1.
                    ;; That means, running (shell-command LIST) may not show
                    ;; the output of all the commands (Bug#23206).
                    ;; Add 'wait' to force those POSIX shells to wait until
                    ;; all commands finish.
                    (or (and parallel-in-background (not w32-shell)
                             "&wait")
                        "")))
Unfortunately, "parallel-in-background" is true even if there is only one command to be run (because there is only one selected file) as long as the command does not contain the character "*":

               (sequentially (string-match "[ \t]*;[ \t]*\\'" command))
               (parallel-in-background
                    (and in-background (not sequentially) (not (eq system-type 'ms-dos))))

As a result, the original single command now becomes a background command (by the addition of "& wait") and it loses access to standard input (it is implicitly run with an empty standard input). If the command asks for a confirmation prompt or a password, there is no way to provide that input. A simple though somewhat silly way to demonstrate the problem is by comparing the following two commands run using dired-do-async-shell-command on a single selected file (say 1.txt)

First command with "*" in the command line works as expected

       cat - * >2.txt

With this command, the *Async Shell Command* buffer waits for us to type in whatever lines that we want. When we terminate the input with Control-D (EOF), the command concatenates the inputs lines with 1.txt and writes the result to 2.txt.

Second command without "*" in the command line does NOT work as expected

       cat - >2.txt

With this command, the command runs without waiting for any input, and simply copies 1.txt to 2.txt because standard input is implicitly empty.

My suggestion is that the definition of "parallel-in-background" in dired-shell-stuff-it should include an additional test that the variable "file-list" contains more than one file.

-----------------------------------------------------

In GNU Emacs 26.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.8)
 of 2019-04-12 built on juergen
Windowing system distributor 'The X.Org Foundation', version 11.0.12005000
Configured using:
 'configure --prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib
 --localstatedir=/var --with-x-toolkit=gtk3 --with-xft --with-modules
 'CFLAGS=-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong
 -fno-plt' CPPFLAGS=-D_FORTIFY_SOURCE=2
 LDFLAGS=-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now'

Configured features:
XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GSETTINGS GLIB
NOTIFY ACL GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB
TOOLKIT_SCROLL_BARS GTK3 X11 XDBE XIM MODULES THREADS LIBSYSTEMD LCMS2

Important settings:
  value of $LC_COLLATE: en_US.utf8
  value of $LC_MONETARY: en_IN.UTF-8
  value of $LC_NUMERIC: en_IN.UTF-8
  value of $LC_TIME: en_IN.UTF-8
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix






             reply	other threads:[~2019-06-22 12:37 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-22 12:37 Prof Jayanth R Varma [this message]
2022-05-18 14:22 ` bug#36331: 26.2; command run using dired-do-async-shell-command cannot take any input Lars Ingebrigtsen
2022-05-18 15:44   ` Eli Zaretskii
2022-05-19 23:36     ` Lars Ingebrigtsen
2022-05-20  3:32       ` Michael Heerdegen
2022-05-20  8:37         ` Lars Ingebrigtsen
2022-05-21  1:58           ` Michael Heerdegen

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=87mui9ztg8.fsf@JRVLAPTOP.i-did-not-set--mail-host-address--so-tickle-me \
    --to=jrvarma@gmail.com \
    --cc=36331@debbugs.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 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).