🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #4095

Re: Why can't I use xargs emacs?

#4095
From: Pascal J. Bourguignon
Date: Tue, 02 Feb 2010 22:56
45 lines
2756 bytes
Adam Funk <a24061@ducksburg.com> writes:

> The emacs command can take a list of filename arguments, so why can't
> I get xargs to work with it?
>
> $ find -name '*.txt' |xargs emacs -nw
> emacs: standard input is not a tty
>
> $ grep -rl 'foo' some/path  |xargs emacs -nw
> emacs: standard input is not a tty

emacs is an interactive program.  It expects its stdin and stdout to
be hooked to the terminal, where it can display a character matrix,
and from which it can read user input.

When you use a pipe to send paths to xargs, you disconnect the
terminal from the stdin, and replace it with a pipe.  When xargs forks
and exec emacs, emacs inherit this pipe as stdin, and cannot get user
input, but will get instead further path from grep.

% echo hello > file ; ( echo -b ; echo file ) | xargs -L 1 cat 
hello


To open several files in emacs, you could either use emacsclient, or
an emacs lisp script.

Launch emacs in a separate terminal: xterm -e emacs -nw & 
In emacs, start the server:          M-x server-start RET
In a shell, you can then type:       find -name '*.txt' | xargs emacsclient -n



Simplier would be to just open the file in emacs:

Launch emacs:  emacs -nw 
Then type: C-x C-f *.txt RET


For the second case, you could type:
M-: (map nil 'find-file (split-string (shell-command-to-string "grep -rl 'foo' some/path") "\n")) RET


-- 
__Pascal Bourguignon__
Technical Details
Message-ID: <87sk9jw8jw.fsf@informatimago.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
References: <p4em37xiau.ln2@news.ducksburg.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 39ae015015,546aec423372e37b
X-Google-Attributes: gid39ae015015,public,usenet
X-Google-NewGroupId: yes
X-Google-Language: ENGLISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: pjb@informatimago.com (Pascal J. Bourguignon)
Newsgroups: comp.unix.shell,gnu.emacs.help
Subject: Re: Why can't I use xargs emacs?
Date: Tue, 02 Feb 2010 23:56:51 +0100
Organization: Informatimago
Lines: 45
Message-ID: <87sk9jw8jw.fsf@informatimago.com>
References: <p4em37xiau.ln2@news.ducksburg.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Trace: individual.net 59jfVzfjP1/Lhg20ywZaegLpQwL0OB3cJOL+F54/9DrnRLFGQw
Cancel-Lock: sha1:NTZjMWNhNTcxZjg0YWU0Y2Y2N2M2ZDViMzFlYzllOGFlZjZmMGQ2MA== sha1:kmZ1Hl/GZ446VYRX2Ptd3hSwtDg=
Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA
      oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9
      033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac
      l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR
      mV+hO/VvFAAAAABJRU5ErkJggg==
X-Accept-Language:         fr, es, en
X-Disabled: X-No-Archive: no
User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.3 (darwin)