After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 121891 - implement input from command line pipe
implement input from command line pipe
Status: RESOLVED FIXED
Product: gedit
Classification: Applications
Component: general
2.13.x
Other All
: High enhancement
: ---
Assigned To: Gedit maintainers
Gedit maintainers
: 147256 160255 361987 593383 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2003-09-10 11:56 UTC by Mattia Belletti
Modified: 2011-10-05 18:45 UTC
See Also:
GNOME target: ---
GNOME version: 2.13/2.14


Attachments
Proposed patch (2.64 KB, patch)
2004-07-13 10:20 UTC, Muktha
none Details | Review
prototype patch (11.04 KB, patch)
2004-10-18 22:46 UTC, Paolo Borelli
needs-work Details | Review
Patch to handle commandline pipes through GIOChannel (10.31 KB, patch)
2005-01-18 09:59 UTC, Santhosh Hiriyur Shankar
needs-work Details | Review
prototype patch #2 (13.06 KB, patch)
2005-09-22 14:17 UTC, Paolo Borelli
none Details | Review

Description Mattia Belletti 2003-09-10 11:56:10 UTC
Description of Problem:
Even if in the README it's said that gedit accepts
input pipe from command line, it seems it doesn't.
I've made myself sure that there was

Steps to reproduce the problem:
1. 'ls | gedit' in a non-empty directory

Actual Results:
Nothing change in gedit from starting it with a
simple 'gedit'.


Expected Results:
gedit starts with a window in which there's the
output of ls

How often does this happen? 
Always
Comment 1 Paolo Maggi 2003-10-01 10:25:08 UTC
It works for me.

Which version of gedit are you using? On which distro?

Comment 2 Paolo Maggi 2003-12-20 10:25:22 UTC
Mattia: ?
Comment 3 Paolo Maggi 2004-01-02 01:13:04 UTC
I think we should add a "-"command line parameter like in vi
Comment 4 Rob Shinn 2004-02-05 01:35:43 UTC
Doesn't work for me either.  The manpage says that gedit accepts
pipes, it does not do anything when I give it a pipe. I'm using gedit
2.4.1 on Gnome 2.4.1 on Gentoo Linux 1.4 (x86).

Comment 5 Paolo Borelli 2004-02-21 20:13:39 UTC
cvs HEAD here: if I don't have any gedit windows open, ls | gedit
doesn't work, but if I first run gedit in a terminal and then in
another terminal I run ls | gedit then the second doc contains the
output of ls just fine.
Comment 6 Tim Potter 2004-03-30 07:25:04 UTC
I can confirm that behaviour.  If a gedit window does not already exist, the 'ls
| gedit' just brings up a blank window.
Comment 7 Matt Endebrock 2004-06-09 18:23:37 UTC
I can also confirm this bug. This bug is still present in Gnome 2.6.0 running on
Fedora Core 2 (i386).

As a check, I enabled debugging via the "--debug" option on the command line,
one with piped input to gedit and another with no input. I diff'ed the resultant
files, which came back as identical.

As mentioned before, if a prior copy of gedit is running and another initiated
with piped input, behavior is as described in the man page.
Comment 8 Paolo Borelli 2004-06-09 18:43:18 UTC
for the record: it looks like the behavior is due to bad timings interactions.

Anyway the current code is pretty hackish, probably the proper way to do it is
using gtkiochannels which can integrate nicely with gtk main loop.
Comment 9 Muktha 2004-07-13 10:20:37 UTC
Created attachment 29502 [details] [review]
Proposed patch
Comment 10 Paolo Maggi 2004-07-13 12:04:58 UTC
*** Bug 147256 has been marked as a duplicate of this bug. ***
Comment 11 Paolo Borelli 2004-10-18 22:44:15 UTC
here it is a first cut of how I think this should be properly implemented (with
GIOChannels)

NB: the patch works but it's just a prototype, among other things it probably
leaks and doesn't remove all the old code.

Suggestion are more than welcome on various issues:
- how to do proper error reporting
- should we emit DOCUMENT_LOADED signal? and LOADING?
- when should we close the Channel?
- how should this integrate with the Application server (it actually seems to
automagically work, but...)
- whatever comes tpyour mind
Comment 12 Paolo Borelli 2004-10-18 22:46:18 UTC
Created attachment 32748 [details] [review]
prototype patch
Comment 13 Paolo Borelli 2004-12-03 00:48:56 UTC
*** Bug 160255 has been marked as a duplicate of this bug. ***
Comment 14 Khasim Shaheed 2005-01-11 05:44:58 UTC
It is still there in Gnome 2.9.3. It is just opening a blank window in gedit.
Comment 15 Santhosh Hiriyur Shankar 2005-01-18 09:57:44 UTC
I'm attaching a patch which makes use of GIOChannel to handle commandline pipes. 
However, I need refinement on the below issues:
 1. To use option --read-stdin (or something liek this) to read commandline
pipes or to use just "-" as vi does? 
 2. What needs to be done when user specifies the option (--read-stdin or just
-) without any pipe, for example: 
    gedit --read-stdin  (or) gedit - 
 3. Comments are welcome to improve the code in patch.   
Comment 16 Santhosh Hiriyur Shankar 2005-01-18 09:59:30 UTC
Created attachment 36163 [details] [review]
Patch to handle commandline pipes through GIOChannel
Comment 17 Paolo Maggi 2005-01-21 13:46:12 UTC
1. I think you should use "-" as vim

2. In this case you should wait for a timeout (for example 60 secs) and then
give up.

3. I have not read the code.
Comment 18 Paolo Borelli 2005-01-23 21:03:04 UTC
Comment on attachment 36163 [details] [review]
Patch to handle commandline pipes through GIOChannel

santhu_: I'm marking the patch as needs work so that it doesn't show up in the
unreviewed patches report.

As I told you on irc I have not looked at it accurately, but from a quick look
there are some things which need to be changed.

- I don't like the use of a global variable to hold the data.

- I don't like that we have gtk_main in an util function

On a way less important level there is the fact that you are not using th
preferred codying stile, in particulare

"if( foo )" vs "if (foo)"


it would be very helpful for reviewing the code properly if you could do the
following two things:

- provide the core function which retrieves the stdin dta separatelly, so that
it is easier to read (ideally in a small test program, which takes stuff from
stdin and fills a text view, but I guess I'm asking too much ;)

- summarize the call chain (in other words who calls who) of the two cases
(first gedit instance and following ones)
Comment 19 Paolo Maggi 2005-02-07 17:03:50 UTC
It is too late to fix this bug for gnome 2.10.0.

I'm going to punt it.
Comment 20 Daniel Holbach 2005-09-19 11:19:30 UTC
Was this fixed in 2.12.0 or will we get it for 2.12.1?
Comment 21 Paolo Borelli 2005-09-19 11:57:27 UTC
Nope, all of our attention has been on http://live.gnome.org/Gedit_2fNewMdi and
this issue has dropped off of our radar and it isn't going going to reach the
top of our todo list anytime soon.

If anyone wants to give it a try, he's more then welcome to do so: it would need
to be almost a rewrite of the feature, given that both the file loading code
changed in new_mdi and the use of bonobo-activation-server for IPC was dropped.


(daniel, I took the liberty of adding ou to CC since you asked the question,
feel free to remove yourself)
Comment 22 Paolo Borelli 2005-09-22 14:17:06 UTC
Created attachment 52506 [details] [review]
prototype patch #2

As usual when I say something is way down on my todo list I end up poking at it
:)

Anyway, here is another prototype patch which implements part of the
functionality for the new_mdi branch. The patch is incomplete because it still
needs some work and in particular we need to find a way to make it work with
bacon-message-connection.

The patch adds the ability to gedit-document-loader to load files from stdin
using GIOChannels.

Minor things that still needs to be done:
- check the code for correctness
- do not leak the GIOChannel in the loader destructor
- fix some assertions in the caller-side (gedit-document) about the uri beiing
null etc
- properly add api to gedit-window etc (the call chain goes like this: main ->
gedit_window_new_tab_from_stdin -> gedit_tab_new_from_stdin ->
gedit_doc_load_stdin -> gedit_doc_loader_load_stdin)

Major issues:
- we need to decide how to design the command line interface: the current "ls |
gedit" doesn't cut it because stdin has to be checked every time. Vim use '-'
to indicate stdin. However '-' gets eat by popt... as a temporary solution my
patch uses --stdin, that is "ls | gedit --stdin"
- We need to design a way to make it work when gedit is launched a second time:
in that case the stdin has to be passed to the running gedit instance... the
easy/ugly way is collecting the data client side and then pass it to the server
but that sucks because it introduces buffering. The better way is to splice the
stdin from the client to the server, using a pipe or some other UNIX gymnastic
I don't know about :)
Comment 23 Jose Dapena Paz 2005-09-22 19:30:57 UTC
A way to solve the problem with the second instance of gedit could be creating a
IPC fifo (with mkfifo), and sending its file name through the bacon. The server
would only have to read from the fifo and close it when it's done. The client
would pass the contents of its stdin to the fifo.
Comment 24 Paolo Borelli 2005-09-22 20:36:05 UTC
[some context for Jose's comment so that it's more clear if I read it again in
the next weeks]

Jose pointed out that the "server" (the running instance of gedit) cannot just
read from stdin when a client is launched, since at least in theory there may be
more than one client reading from stdin at the same time.

Named fifo sounds like a viable solution if we stick[1] to bacon-message-connection.


[1] the obvious alternative being D-BUS
Comment 25 Daniel Holbach 2006-08-02 10:18:08 UTC
https://launchpad.net/distros/ubuntu/+source/gedit/+bug/9054 is the Ubuntu bug about that.
Comment 26 Paolo Borelli 2006-10-14 08:55:51 UTC
*** Bug 361987 has been marked as a duplicate of this bug. ***
Comment 27 Lonnie Best 2007-05-15 02:40:28 UTC
This bug remains in Ubuntu 7.04: Piping to gedit opens a gedit, but the document is completely blank.
Comment 28 Nicholas J Kreucher 2007-10-17 20:04:37 UTC
This would be a VERY nice feature to have... would make gedit more accessible to the command line junky.
Comment 29 Mike Rooney 2008-05-11 03:59:15 UTC
Hello, I am using Ubuntu 8.04 (gedit 2.22.1), and would love to see piping work. I find myself wanting to do "bzr diff | gedit" all the time, for example. Let me know if there is anything I can do to help. If it is documented that it should work this way, it seems rather important that it does.

Thanks for the great text editor :]
Comment 30 Frank Dana 2009-04-08 04:30:35 UTC
Newly-created bugs.redhat.com bz# 494781 tracks this in fedora. ( http://bugzilla.redhat.com/show_bug.cgi?id=494781 )

If the functionality is not going to be a simple fix (which PBorelli's migration of this to "Enhancement Request" at the start of this year seems to indicate it's not) and may never actually materialize, could the GEdit documentation section that describes the feature be removed? I think it better manages user expectations to avoid teasing them with features that don't actually exist. The documentation can be put back when the functionality actually exists. :)

(The section in question is "Features/Piping the Output of a Command to a File" in the GEdit manual. Standard yelp GNOME documentation, Utilities category.)


...Mind you, it's a nice change from the usual situation in software documentation: the functionality exists, but documentation on it doesn't catch up until months later. I think this case overcompensates a bit too far in the other direction, is all.  ;)
Comment 31 Paolo Borelli 2009-08-29 10:58:59 UTC
*** Bug 593383 has been marked as a duplicate of this bug. ***
Comment 32 jessevdk@gmail.com 2010-05-15 13:30:06 UTC
This problem has been fixed in the development version. The fix will be available in the next major software release. Thank you for your bug report.
Comment 33 Brion Vibber 2011-10-05 18:29:13 UTC
Just to confirm -- this *does* appear to work now in Gnome 3.0.6.

Still seems missing as of the Gnome 2.30.4 in Ubuntu 11.04 though, so presumably it didn't make it into any Gnome 2.x version?
Comment 34 Ignacio Casal Quinteiro (nacho) 2011-10-05 18:45:44 UTC
nop, this was implemented for the 3.0 version.