unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* problem with call-process function
@ 2015-11-30 17:28 Bostjan Vilfan
  2015-11-30 18:12 ` Eli Zaretskii
  2015-12-01  0:15 ` Emanuel Berg
  0 siblings, 2 replies; 3+ messages in thread
From: Bostjan Vilfan @ 2015-11-30 17:28 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 5543 bytes --]

Hello,
I'm using emacs version 24.5.1 on Windows 10, and I encountered the following problem. It's probably due to some misunderstanding so I hope someone can straighten me out:

I tried to use the  function call-process (Section 36.3 of Emacs Lisp manual), the manual entry for which I am copying for convenience:


START OF COPY
 -- Function: call-process program &optional infile destination display
          &rest args
     This function calls PROGRAM and waits for it to finish.

     The current working directory of the subprocess is
     ‘default-directory’.

     The standard input for the new process comes from file 
     INFILE if INFILE is not ‘nil’, and from the null device 
     otherwise.  The  argument DESTINATION says where to 
     put the process output.  Here  are the possibilities:

     a buffer
          Insert the output in that buffer, before point.  This 
          includes  both the standard output stream and the 
          standard error stream of the process.

     a string
          Insert the output in a buffer with that name, before point.

     ‘t’
          Insert the output in the current buffer, before point.

     ‘nil’
          Discard the output.

     0
          Discard the output, and return ‘nil’ immediately without
          waiting for the subprocess to finish.

          In this case, the process is not truly synchronous, since 
          it  can run in parallel with Emacs; but you can think of it 
          as synchronous in that Emacs is essentially finished with
          the  subprocess as soon as this function returns.

          MS-DOS doesn’t support asynchronous subprocesses, 
          so this  option doesn’t work there.

     ‘(:file FILE-NAME)’
          Send the output to the file name specified, overwriting it 
          if it already exists.

     ‘(REAL-DESTINATION ERROR-DESTINATION)’
          Keep the standard output stream separate from the 
          standard error stream; deal with the ordinary output as 
          specified by REAL-DESTINATION, and dispose of the 
          error output according to
          ERROR-DESTINATION.  If ERROR-DESTINATION is 
          ‘nil’, that means to discard the error output, ‘t’ means mix
          it with the  ordinary output, and a string specifies a file 
          name to  redirect error output into.

          You can’t directly specify a buffer to put the error output
          in; that is too difficult to implement.  But you can achieve
          this result by sending the error output to a temporary file
          and then inserting the file into a buffer.

     If DISPLAY is non-‘nil’, then ‘call-process’ redisplays the 
     buffer as output is inserted.  (However, if the coding system
     chosen for decoding output is ‘undecided’, meaning deduce
     the encoding from the actual data, then redisplay 
     sometimes cannot continue once non-ASCII characters are 
     encountered.  There are fundamental reasons why it is hard
     to fix this; see *note Output from
     Processes::.)

     Otherwise the function ‘call-process’ does no redisplay, and
     the  results become visible on the screen only when Emacs
     redisplays that buffer in the normal course of events.

     The remaining arguments, ARGS, are strings that specify 
     command line arguments for the program.

     The value returned by ‘call-process’ (unless you told it not
     to wait) indicates the reason for process termination.  A 
     number gives     the exit status of the subprocess; 0 means 
     success, and any other value means failure.  If the process 
     terminated with a signal, ‘call-process’ returns a string 
    describing the signal.

     In the examples below, the buffer ‘foo’ is current.

          (call-process "pwd" nil t)
               ⇒ 0

          ---------- Buffer: foo ----------
          /home/lewis/manual
          ---------- Buffer: foo ----------

          (call-process "grep" nil "bar" nil "lewis" "/etc/passwd")
               ⇒ 0

          ---------- Buffer: bar ----------
          lewis:x:1001:1001:Bil Lewis,,,,:/home/lewis:/bin/bash

          ---------- Buffer: bar ----------

     Here is an example of the use of ‘call-process’, as used to 
     be found in the definition of the ‘insert-directory’ function:

          (call-process insert-directory-program nil t nil switches
                        (if full-directory-p
                            (concat (file-name-as-directory file) ".")
                          file))
END OF COPY

The simple cases are straightforward enough. For example,

(call-process "myprog.exe" nil t nil <additional arguments>)

will place the output plus error output of myprog.exe into the 
current buffer. However, when I tried to separate the output  
from the error output, I ran into problems. According to my 
reading of the manual (see above) one should replace 
"destination" (1st line of manual text) with ‘(REAL-DESTINATION ERROR-DESTINATION)’ where REAL-DESTINATION
and ERROR-DESTINATION are one of the given alternatives; for example:

(call-process "myprog.exe" nil (t nil) nil <additional arguments>)

However, the previous line, as well as many other attempts did not work.
Obviously, I am doing something wrong; but what? Thanks in advance for
answers.

Regards,
Bostjan Vilfan

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

* Re: problem with call-process function
  2015-11-30 17:28 problem with call-process function Bostjan Vilfan
@ 2015-11-30 18:12 ` Eli Zaretskii
  2015-12-01  0:15 ` Emanuel Berg
  1 sibling, 0 replies; 3+ messages in thread
From: Eli Zaretskii @ 2015-11-30 18:12 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Mon, 30 Nov 2015 12:28:44 -0500
> From: Bostjan Vilfan <bostjanv@alum.mit.edu>
> 
> (call-process "myprog.exe" nil (t nil) nil <additional arguments>)
> 
> However, the previous line, as well as many other attempts did not work.
> Obviously, I am doing something wrong; but what? Thanks in advance for
> answers.

You need to quote the (t nil) list: '(t nil).



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

* Re: problem with call-process function
  2015-11-30 17:28 problem with call-process function Bostjan Vilfan
  2015-11-30 18:12 ` Eli Zaretskii
@ 2015-12-01  0:15 ` Emanuel Berg
  1 sibling, 0 replies; 3+ messages in thread
From: Emanuel Berg @ 2015-12-01  0:15 UTC (permalink / raw)
  To: help-gnu-emacs

Bostjan Vilfan <bostjanv@alum.mit.edu> writes:

> Hello, I'm using emacs version 24.5.1 on Windows 10,

Mega-gulp!

> The simple cases are straightforward enough.
> For example,
>
> (call-process "myprog.exe" nil t nil <additional> arguments>)
>
> will place the output plus error output of
> myprog.exe into the current buffer. However, when
> I tried to separate the output from the error
> output, I ran into problems. According to my reading
> of the manual (see above) one should replace
> "destination" (1st line of manual text) with
> ‘(REAL-DESTINATION ERROR-DESTINATION)’ where
> REAL-DESTINATION and ERROR-DESTINATION are one of
> the given alternatives; for example:
>
> (call-process "myprog.exe" nil (t nil) nil
> <additional arguments>)

Yeah, you need to quote the (t nil) otherwise it is
not a list with data but a *form*, i.e. a unary
function which named `t' to which you upon invocation
send the argument nil!

It works with '(t nil)

You can try this with this zsh script:

    #!/bin/zsh

    echo "This output is so standard, it even goes to stdout."

    echo "I always do things the opposite way - it is so immature!" >&2

And this Elisp:

    (call-process "~/chatty-program"                  ; the program to run
              nil                                     ; (no INFILE)
              `(,(get-buffer-create "stdout-buffer")  ; create #<buffer stdout-buffer>
                "~/chatty-errors")                    ; send errors to this file
              ) ; evaluate me

The backquote (`) creates a list, only it allows for
evaluation if something is preceeded by a comma (,).

Or, put it like this:

    (list (get-buffer-create "stdout-buffer")
          "~/chatty-errors")

-- 
underground experts united
http://user.it.uu.se/~embe8573




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

end of thread, other threads:[~2015-12-01  0:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-30 17:28 problem with call-process function Bostjan Vilfan
2015-11-30 18:12 ` Eli Zaretskii
2015-12-01  0:15 ` Emanuel Berg

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