help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: About "program" and "command"


From: Pascal J. Bourguignon
Subject: Re: About "program" and "command"
Date: Sun, 24 Mar 2013 15:34:52 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux)

Xue Fuqiao <xfq.free@gmail.com> writes:

> The doc string of `call-process' says:
>
>   Call PROGRAM synchronously in separate process.
>
> The doc string of `call-process-shell-command' says:
>
>   Execute the shell command COMMAND synchronously in separate process.
>
> What's the different of these two functions?  In other words, what's the
> difference of "program" and "command" here?  After searching the
> archives, I found two threads[1][2], but they don't help.  So can I get
> a pointer to information on these two concepts?

Some shell commands are not programs, but built-in routines in the
shell.  Or also, aliases, functions, etc.

Compare:

(let ((buffer (get-buffer-create (generate-new-buffer-name "*test*"))))
   (call-process-shell-command "set" nil  buffer)
   (switch-to-buffer buffer))

with:

(let ((buffer (get-buffer-create (generate-new-buffer-name "*test*"))))
   (call-process "set" nil  buffer)
   (switch-to-buffer buffer))


In some cases, there are both a command and a program so this may be
confusing.  For example, there is /bin/echo and the builtin echo.  They
may behave differently!

Again, compare:

(let ((buffer (get-buffer-create (generate-new-buffer-name "*test*"))))
   (call-process-shell-command "echo" nil  buffer nil "--help")
   (switch-to-buffer buffer))

with:

(let ((buffer (get-buffer-create (generate-new-buffer-name "*test*"))))
   (call-process "echo" nil  buffer nil "--help")
   (switch-to-buffer buffer))


Bash has a builtin named 'command' that skip looking for functions or
aliases, but still runs the built-in command if there's one.

Bash also has a builtin named 'enable' which lets you enable or disable
a builtin command, so it doesn't shadow the programs.

Also since call-process-shell-command uses the shell to interpret the
'command', one can pass several commands separated with semicolon:

(let ((buffer (get-buffer-create (generate-new-buffer-name "*test*"))))
   (call-process-shell-command "echo a ; echo b" nil  buffer)
   (switch-to-buffer buffer))

(let ((buffer (get-buffer-create (generate-new-buffer-name "*test*"))))
   (call-process-shell-command "echo --help ; enable -n echo ; echo --help" nil 
 buffer)
   (switch-to-buffer buffer))

or of course, you can always give the path to the program to avoid the
builtin command:

(let ((buffer (get-buffer-create (generate-new-buffer-name "*test*"))))
   (call-process-shell-command "echo --help ; /bin/echo --help" nil  buffer)
   (switch-to-buffer buffer))

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]