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

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

problem with call-process function


From: Bostjan Vilfan
Subject: problem with call-process function
Date: Mon, 30 Nov 2015 12:28:44 -0500

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

reply via email to

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