unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Bostjan Vilfan <bostjanv@alum.mit.edu>
To: help-gnu-emacs@gnu.org
Subject: problem with call-process function
Date: Mon, 30 Nov 2015 12:28:44 -0500	[thread overview]
Message-ID: <1123318547.39321.1448904524817.JavaMail.help@alum.mit.edu> (raw)

[-- 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

             reply	other threads:[~2015-11-30 17:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-30 17:28 Bostjan Vilfan [this message]
2015-11-30 18:12 ` problem with call-process function Eli Zaretskii
2015-12-01  0:15 ` Emanuel Berg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1123318547.39321.1448904524817.JavaMail.help@alum.mit.edu \
    --to=bostjanv@alum.mit.edu \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).