unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Feature request/wishlist: allowing external processes to accept input in script mode
@ 2005-10-25 23:16 D Goel
  2005-10-25 23:52 ` Andreas Schwab
  2005-10-27  1:29 ` Richard M. Stallman
  0 siblings, 2 replies; 5+ messages in thread
From: D Goel @ 2005-10-25 23:16 UTC (permalink / raw)




Emacs now has a --script option, which allows one to use emacs for all
scripting purposes.

Emacs scripts can call other processes, and those other processes can
call emacs scripts in turn, and so on, just as if the emacs script was
any other bash script.  

... except:

It seems, however, that if one of those external processes requires a
user input, then emacs exits with an error, as seen in the example
below.  Indeed, `call-process' does not seem to allow infile to be
stdin. (Or, did I screw up?)

Can the infile non allow a stdin option when emacs is invoked via a
emacs --script?

---
Example:

Save this as an executable y-or-n-p-my in ~/bin/
----
#!/bin/bash
echo -n "$@" '[y/n] '
read ans

case "$ans" in
    y*|Y*)
	exit 0
	;;
    *)
	exit 1
	;;
esac
----

Now we call the above bash script from an emacs script, in various
ways:

----
#!/usr/local/bin/emacscvs --script


(setq a (call-process "y-or-n-p-my" nil t  t "Question"))
(message "PR1: %S" a)

(with-temp-buffer "*tmp*" 
		  (message "%S" (buffer-string)))




(setq a (call-process-shell-command "y-or-n-p-my Question" nil t  t
"ans"))

(message "PR2: %S" a)
(with-temp-buffer "*tmp*" 
		  (message "%S" (buffer-string)))



(setq a (shell-command-to-string "y-or-n-p-my Question"))


(message "SHELL COMMAND: %S" a)
----

In each case, it all goes fine right until the external process waits
for user input.

Am I missing the right way to call an external process from an emacs
script?   


Sincerely,

DG                                 http://gnufans.net/
--

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

* Re: Feature request/wishlist: allowing external processes to accept input in script mode
  2005-10-25 23:16 Feature request/wishlist: allowing external processes to accept input in script mode D Goel
@ 2005-10-25 23:52 ` Andreas Schwab
  2005-10-26 14:57   ` D Goel
  2005-10-27  1:29 ` Richard M. Stallman
  1 sibling, 1 reply; 5+ messages in thread
From: Andreas Schwab @ 2005-10-25 23:52 UTC (permalink / raw)
  Cc: emacs-devel

"D Goel" <deego@gnufans.org> writes:

> Now we call the above bash script from an emacs script, in various
> ways:
>
> ----
> #!/usr/local/bin/emacscvs --script
>
>
> (setq a (call-process "y-or-n-p-my" nil t  t "Question"))

You explicitly tell that input for the process should come from /dev/null,
so this works as expected.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

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

* Re: Feature request/wishlist: allowing external processes to accept input in script mode
  2005-10-25 23:52 ` Andreas Schwab
@ 2005-10-26 14:57   ` D Goel
  2005-10-26 15:54     ` Kevin Rodgers
  0 siblings, 1 reply; 5+ messages in thread
From: D Goel @ 2005-10-26 14:57 UTC (permalink / raw)
  Cc: emacs-devel



Andreas Schwab <schwab@suse.de> writes:

> "D Goel" <deego@gnufans.org> writes:
>
>> Now we call the above bash script from an emacs script, in various
>> ways:
>>
>> ----
>> #!/usr/local/bin/emacscvs --script
>>
>>
>> (setq a (call-process "y-or-n-p-my" nil t  t "Question"))
>
> You explicitly tell that input for the process should come from /dev/null,
> so this works as expected.

I certainly agree with that. I supplied nil for infile above.
My question is: what argument can I supply as infile so that when the
external process expects an input, it actually accepts input from
stdin?

As far as I can tell, infile can only be a file, or nil. 

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

* Re: Feature request/wishlist: allowing external processes to accept input in script mode
  2005-10-26 14:57   ` D Goel
@ 2005-10-26 15:54     ` Kevin Rodgers
  0 siblings, 0 replies; 5+ messages in thread
From: Kevin Rodgers @ 2005-10-26 15:54 UTC (permalink / raw)


D Goel wrote:
> 
> Andreas Schwab <schwab@suse.de> writes:
> 
> 
>>"D Goel" <deego@gnufans.org> writes:
>>
>>
>>>Now we call the above bash script from an emacs script, in various
>>>ways:
>>>
>>>----
>>>#!/usr/local/bin/emacscvs --script
>>>
>>>
>>>(setq a (call-process "y-or-n-p-my" nil t  t "Question"))
>>
>>You explicitly tell that input for the process should come from /dev/null,
>>so this works as expected.
> 
> 
> I certainly agree with that. I supplied nil for infile above.
> My question is: what argument can I supply as infile so that when the
> external process expects an input, it actually accepts input from
> stdin?
> 
> As far as I can tell, infile can only be a file, or nil. 

Did you try "/dev/stdin" or "/dev/fd/0"?

-- 
Kevin Rodgers

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

* Re: Feature request/wishlist: allowing external processes to accept input in script mode
  2005-10-25 23:16 Feature request/wishlist: allowing external processes to accept input in script mode D Goel
  2005-10-25 23:52 ` Andreas Schwab
@ 2005-10-27  1:29 ` Richard M. Stallman
  1 sibling, 0 replies; 5+ messages in thread
From: Richard M. Stallman @ 2005-10-27  1:29 UTC (permalink / raw)
  Cc: emacs-devel

    Can the infile non allow a stdin option when emacs is invoked via a
    emacs --script?

There is probably no way to do this now, but I suppose call-process
could have some way of saying "inherit stdin" for the batch case.  (If
"/dev/stdin" doesn't do the job.)

If /dev/stdin does work, maybe we should document that.

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

end of thread, other threads:[~2005-10-27  1:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-25 23:16 Feature request/wishlist: allowing external processes to accept input in script mode D Goel
2005-10-25 23:52 ` Andreas Schwab
2005-10-26 14:57   ` D Goel
2005-10-26 15:54     ` Kevin Rodgers
2005-10-27  1:29 ` Richard M. Stallman

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).