简体   繁体   中英

Emacs `start-process` seems to mangle process output

I am at the bottom of a problem - I don't see how to dig any deeper because I am now running start-process from the process.C file. Which is in Emacs internals and the next step seem to be looking at the C code.

Here's the my problem. When I run

(let ((default-directory "C:/Users/esharapov/.emacs.d/"))
  (apply 'start-process "ag" (get-buffer-create "test")
         "c:\\App\\emacs\\libexec\\emacs\\24.5\\i686-pc-mingw32\\cmdproxy.exe"
         (list "-c" "\"ag\" \"--nocolor\"  \"--literal\" \"--line-number\" \"--smart-case\" \"--nogroup\" \"--column\" \"--stats\" \"--\" \"keymap-on\" \".\"")))

I get in the buffer following output

194:15:    (defmacro keymap-on-key (name keys)
233:9:       (keymap-on-key ctl-x-f-map "C-x f")
572:7:     (keymap-on-key ctl-z-w-map "C-z w")
194:15:    (defmacro keymap-on-key (name keys)

233:9:       (keymap-on-key ctl-x-f-map "C-x f")

572:7:     (keymap-on-key ctl-z-w-map "C-z w")

6 matches
382 files searched
8993756 bytes searched
0.446822 seconds

Process ag finished

If I run it in the Windows command prompt as

c:\\App\\emacs\\libexec\\emacs\\24.5\\i686-pc-mingw32\\cmdproxy.exe /c "C:\\App\\bin\\ag.exe --nocolor  --literal --line-number --smart-case --nogroup --column --stats -- keymap-on ."

I get following output

#configuration.org#:194:15:    (defmacro keymap-on-key (name keys)
#configuration.org#:233:9:       (keymap-on-key ctl-x-f-map "C-x f")
#configuration.org#:572:7:     (keymap-on-key ctl-z-w-map "C-z w")
configuration.org:194:15:    (defmacro keymap-on-key (name keys)
configuration.org:233:9:       (keymap-on-key ctl-x-f-map "C-x f")
configuration.org:572:7:     (keymap-on-key ctl-z-w-map "C-z w")
6 matches
382 files searched
8993756 bytes searched
0.483917 seconds

Noticed the difference ? When I use start-process the file name is being removed from the process output. Does anyone know what's the issue here ?

UPDATE

I conducted few more experiments comparing output of various commands in the CMD shell and in Emacs shell . One obvious contender was grep command

(let ((default-directory "C:/Users/esharapov/Dev/Test/"))
  (apply 'start-process "grep" (get-buffer-create "test") "c:\\App\\emacs\\libexec\\emacs\\24.5\\i686-pc-mingw32\\cmdproxy.exe" (list "-c" "\"grep\" \"-nH\"  \"-e\" \"Metlife\" \"*.txt\"")))

Prints

Evgeniy_Review.txt:192:   1. Finishing Harmony Docker container and presenting it to the Metlife SWAT
Evgeniys_20141031.txt:16:   1. Finishing Harmony Docker container and presenting it to the Metlife SWAT

Process grep finished

The output of the console is identical

C:\Users\esharapov\Dev\Test>grep -nH -e Metlife *.txt
Evgeniy_Review.txt:192:   1. Finishing Harmony Docker container and presenting it to the Metlife SWAT
Evgeniys_20141031.txt:16:   1. Finishing Harmony Docker container and presenting it to the Metlife SWAT

Now for ag command

(let ((default-directory "C:/Users/esharapov/Dev/Test/"))
  (apply 'start-process "ag" (get-buffer-create "test") "c:\\App\\emacs\\libexec\\emacs\\24.5\\i686-pc-mingw32\\cmdproxy.exe" (list "-c" "\"ag\" --nocolor --nogroup \"Metlife\" .")))

Prints out the following:

   1. Finishing Harmony Docker container and presenting it to the Metlife SWAT
   1. Finishing Harmony Docker container and presenting it to the Metlife SWAT

Process ag finished

While in the console (CMD shell)

C:\Users\esharapov\Dev\Test>ag --nocolor --nogroup Metlife .
Evgeniys_20141031.txt:16:   1. Finishing Harmony Docker container and presenting it to the Metlife SWAT
Evgeniy_Review.txt:192:   1. Finishing Harmony Docker container and presenting it to the Metlife SWAT

Seems like replacing cmdproxy with say bash from Git for Windows or cmd doesn't make a difference and results are the same.

So, it is something in ag console command that makes a difference. On the other hand what's going on that start-process output is different from cmd output ?

Versions:

  • Microsoft Windows [Version 6.3.9600]
  • GNU Emacs 24.5.1 (i686-pc-mingw32) of 2015-04-11 on LEG570

I would guess that you need to include the --filename parameter to ag to fix that.

As the reason of the divergence of outputs, my guess is that it would be related to environment variables. Those might different between emacs and prompt (the path of ag binary, the HOME where ag looks for its defaults, etc).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM