Subject: Re: bug#12689: 24.2; Eshell ${cmd} substitution

From: samer <[email-masked]>
Date: Sun, 14 Dec 2014 04:44:04 -0800

There are two issues contained in this bug: eshell-plain-command doesn't
wait for the process to finish before returning, and echo parses output
from subcommands as lisp objects instead of as args.

The following patch makes eshell wait for external commands to finish
before getting their output.

The second bug is more complicated. Arguments are parsed with
eshell-parse-arguments, which takes into account eshell's rules and
syntax. When things are run in subshells, they're converted to lisp
objects with eshell-convert, with no further processing. For example,
for the command "echo ${/bin/echo hello there}" the subshell will return
"hello there", which is seen as a single argument by the outer "echo".
This isn't a big deal, but it means some constructions won't make sense.
For instance:

$ echo hello there
("hello" "there")
$ echo ${/bin/echo hello there}
hello there

I tried hacking with eshell-parse-variable-ref to parse the arguments
correctly, but it's trickier than it seems at first glance, so I'll work
on it later. This patch gets us 90% of the way there, though.

Best,
Samer

---- Patch below ----

Changes from HEAD to working tree
2 files changed, 6 insertions(+), 1 deletion(-)
  lisp/ChangeLog         |    5 +++++
  lisp/eshell/esh-cmd.el |    2 +-

	Modified   lisp/ChangeLog
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 45ba279..aa00661 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,8 @@
+2014-12-14  Samer Masterson  <[email-masked]>
+
+	* eshell/esh-cmd.el (eshell-plain-command): Wait for subprocess to
+	finish before evaluating command (bug#12680).
+
  2014-11-28  Martin Rudalics  <[email-masked]>

  	Fix two issues around help-window-select.  (Bug#11039) (Bug#19012)
	Modified   lisp/eshell/esh-cmd.el
diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el
index d20b66a..f17aa41 100644
--- a/lisp/eshell/esh-cmd.el
+++ b/lisp/eshell/esh-cmd.el
@@ -1241,7 +1241,7 @@ or an external command."
  	     (or esym eshell-prefer-lisp-functions
  		 (not (eshell-search-path command))))
  	(eshell-lisp-command sym args)
-      (eshell-external-command command args))))
+      (eshell-wait-for-process (eshell-external-command command 
args)))))

  (defun eshell-exec-lisp (printer errprint func-or-form args form-p)
    "Execute a lisp FUNC-OR-FORM, maybe passing ARGS.