diff -pNaur old/gedit2.c new/gedit2.c
--- gedit/gedit2.c	2005-01-18 14:52:54.646902688 +0530
+++ gedit/gedit2.c	2005-01-18 14:42:36.227916664 +0530
@@ -66,6 +66,12 @@ static gboolean quit_option = FALSE;
 static gboolean new_window_option = FALSE;
 static gboolean new_document_option = FALSE;
 
+/* read_stdin_option is for comman line option --read-stdin */
+static gboolean read_stdin_option = FALSE;
+
+/* stdin_data is to point to the data read from pipe on stdin */
+gchar *stdin_data;
+
 typedef struct _CommandLineData CommandLineData;
 
 struct _CommandLineData
@@ -95,6 +101,8 @@ static const struct poptOption options [
 	{ "new-document", '\0', POPT_ARG_NONE, &new_document_option, 0,
 	  N_("Create a new document in an existing instance of gedit"), NULL },
 
+	{"read-stdin", '\0', POPT_ARG_NONE, &read_stdin_option, 0, N_("Read piped data from another command through stdin"), NULL},
+	  
 	{NULL, '\0', 0, NULL, 0}
 };
 
@@ -123,8 +131,13 @@ gedit_load_file_list (CommandLineData *d
 	while (gtk_events_pending ())
 		gtk_main_iteration ();
 
-	res = gedit_file_open_from_stdin (NULL);
-
+	if(read_stdin_option)
+	{
+		res = gedit_file_open_from_stdin (NULL);
+		/* No need to open new file */
+		if(data == NULL)
+			return ;
+	} 
 	if (data == NULL) 
 	{
 		gedit_file_new ();
@@ -197,7 +210,6 @@ gedit_handle_automation (GnomeProgram *p
 	CommandLineData *data;
 	GNOME_Gedit_URIList *uri_list;
 	GSList *list;
-	gchar *stdin_data;
 	int i;
 
         CORBA_exception_init (&env);
@@ -250,49 +262,28 @@ gedit_handle_automation (GnomeProgram *p
 		g_slist_free (data->file_list);
 		g_free (data);
 	}
-
-	stdin_data = gedit_utils_get_stdin ();
-
-	if (stdin_data != NULL && strlen (stdin_data) > 0)
+	
+	/* Handle data from stdin, only if option --read-stdin is specified at 
+	   command line */
+	if(read_stdin_option)
 	{
-		GError *conv_error = NULL;
-		const GeditEncoding *encoding;
-		gchar *converted_text;
-
-		if (gedit_encoding_get_current () != gedit_encoding_get_utf8 ())
-		{
-			if (g_utf8_validate (stdin_data, -1, NULL))
-			{
-				converted_text = stdin_data;
-				stdin_data = NULL;
-
-				encoding = gedit_encoding_get_utf8 ();
-			}
-			else
-			{
-				converted_text = NULL;
-			}
-		}
-		else
-		{	
-			encoding = gedit_encoding_get_current ();
-				
-			converted_text = gedit_convert_to_utf8 (stdin_data,
-								-1,
-								&encoding,
-								&conv_error);
-		}	
+		/* once gedit_utils_get_stdin is returned, stdin_data will point to 
+		   the data read on stdin from pipe. */
+		gedit_utils_get_stdin ();
 		
-		if (converted_text != NULL)
+		if (stdin_data != NULL && strlen (stdin_data) > 0)
 		{
+			/* Open new document */
 			document = GNOME_Gedit_Window_newDocument (window, &env);
-
-			GNOME_Gedit_Document_insert (document, 0, converted_text,
-						     strlen (converted_text), &env);
-
-			g_free (converted_text);
+	
+			 /* insert the data pointed by stdin_data to the
+			   document */
+			GNOME_Gedit_Document_insert (document, 0, stdin_data,
+							     strlen(stdin_data), &env);
+	
+			g_free (stdin_data);
 		}
-	}
+	}	
 
 	if (stdin_data != NULL)
 		g_free (stdin_data);
@@ -300,7 +291,7 @@ gedit_handle_automation (GnomeProgram *p
 	/* at the very least, we focus the active window */
 	GNOME_Gedit_Window_grabFocus (window, &env);
 
-	bonobo_object_release_unref (server, &env);
+	//bonobo_object_release_unref (server, &env);
         CORBA_exception_free (&env);
 
 	/* we never popup a window, so tell startup-notification that
diff -pNaur old/gedit-document.c new/gedit-document.c
--- gedit/gedit-document.c	2005-01-18 14:53:01.267896144 +0530
+++ gedit/gedit-document.c	2005-01-18 14:42:36.252912864 +0530
@@ -1365,64 +1365,21 @@ gedit_document_load (GeditDocument      
 gboolean
 gedit_document_load_from_stdin (GeditDocument* doc, GError **error)
 {
-	gchar *stdin_data;
+	extern gchar *stdin_data;
 	GtkTextIter iter, end;
 	
 	gedit_debug (DEBUG_DOCUMENT, "");
 
 	g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
-	
-	stdin_data = gedit_utils_get_stdin ();
+
+	gedit_utils_get_stdin ();
 
 	if (stdin_data != NULL && strlen (stdin_data) > 0)
 	{
-		GError *conv_error = NULL;
-		const GeditEncoding *encoding;
-		gchar *converted_text;
-
-		if (gedit_encoding_get_current () == gedit_encoding_get_utf8 ())
-		{
-			if (g_utf8_validate (stdin_data, -1, NULL))
-			{
-				converted_text = stdin_data;
-				stdin_data = NULL;
-
-				encoding = gedit_encoding_get_utf8 ();
-			}
-			else
-			{
-				converted_text = NULL;
-			}
-		}
-		else
-		{	
-			encoding = gedit_encoding_get_current ();
-				
-			converted_text = gedit_convert_to_utf8 (stdin_data,
-								-1,
-								&encoding,
-								&conv_error);
-		}	
-		
-		if (converted_text == NULL)
-		{
-			/* bail out */
-			if (conv_error == NULL)
-				g_set_error (error, GEDIT_DOCUMENT_IO_ERROR,
-					     GEDIT_ERROR_INVALID_UTF8_DATA,
-					     _("Invalid UTF-8 data"));
-			else
-				g_propagate_error (error, conv_error);
-
-			g_free (stdin_data);
-
-			return FALSE;
-		}
-
 		gedit_document_begin_not_undoable_action (doc);
 		/* Insert text in the buffer */
 		gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc), &iter, 0);
-		gtk_text_buffer_insert (GTK_TEXT_BUFFER (doc), &iter, converted_text, -1);
+		gtk_text_buffer_insert (GTK_TEXT_BUFFER (doc), &iter, stdin_data, -1);
 
 		/* We had a newline in the buffer to begin with. (The buffer always contains
    		 * a newline, so we delete to the end of the buffer to clean up. */
@@ -1435,12 +1392,8 @@ gedit_document_load_from_stdin (GeditDoc
 
 		gedit_document_end_not_undoable_action (doc);
 		
-		g_free (converted_text);
-	}
-
-	if (stdin_data != NULL)
 		g_free (stdin_data);
-			
+	}
 
 	gedit_document_set_readonly (doc, FALSE);
 	gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (doc), TRUE);
diff -pNaur old/gedit-file.c new/gedit-file.c
--- gedit/gedit-file.c	2005-01-18 14:53:07.067014544 +0530
+++ gedit/gedit-file.c	2005-01-18 14:42:36.252912864 +0530
@@ -779,7 +779,6 @@ gedit_file_open_single_uri (const gchar*
 gboolean
 gedit_file_open_from_stdin (GeditMDIChild *active_child)
 {
-	struct stat stats;
 	gboolean ret = TRUE;
 	GeditDocument *doc = NULL;
 	GError *error = NULL;
@@ -787,11 +786,6 @@ gedit_file_open_from_stdin (GeditMDIChil
 	GeditMDIChild* new_child = NULL;
 
 	gedit_debug (DEBUG_FILE, "");
-	
-	fstat (STDIN_FILENO, &stats);
-	
-	if (stats.st_size  == 0)
-		return FALSE;
 
 	child = active_child;
 	
diff -pNaur old/gedit-utils.c new/gedit-utils.c
--- gedit/gedit-utils.c	2005-01-18 14:53:12.777146472 +0530
+++ gedit/gedit-utils.c	2005-01-18 14:42:36.253912712 +0530
@@ -529,51 +529,128 @@ gedit_utils_convert_search_text (const g
 }
 
 #define GEDIT_STDIN_BUFSIZE 1024
-
-gchar *
-gedit_utils_get_stdin (void)
+static gboolean
+gedit_handle_stdin (GIOChannel *ioc, GIOCondition condition, gchar *data)
 {
-	GString * file_contents;
-	gchar *tmp_buf = NULL;
-	guint buffer_length;
-	GnomeVFSResult	res;
-	fd_set rfds;
-	struct timeval tv;
+	/* This function handles GIO channel. 
+	   Whenever dfata is on stdin, it reads until EOF and 
+	   then assigns global variable stdin_data to point to 
+	   that data and closes GIOChannel and calls gtk_main_quit 
+	   to get out of inner gtk_main function. */
+	static GString *contents;
+	gchar *line;
+	gsize len, pos;
+	static gsize total_len = 0;
+	GError *error = NULL;
+	GIOStatus status;
+
+	extern gchar *stdin_data;
 	
-	FD_ZERO (&rfds);
-	FD_SET (0, &rfds);
+	status = g_io_channel_read_line (ioc, &line, &len, &pos, &error);
+	
+	/*Check for status */
+	switch (status)
+	{
+	case G_IO_STATUS_NORMAL: /*Case Normal - some data is read from stdin*/
+		if (line)
+		{
+			if (!contents)
+				contents = g_string_new (line);
+			else
+				g_string_append (contents, line);
 
-	/* wait for 1/4 of a second */
-	tv.tv_sec = 0;
-	tv.tv_usec = STDIN_DELAY_MICROSECONDS;
+			total_len += len;
+		}
+		g_free (line);
+		return TRUE;
 
-	if (select (1, &rfds, NULL, NULL, &tv) != 1)
-		return NULL;
+	case G_IO_STATUS_AGAIN:
+		return TRUE;
 
-	tmp_buf = g_new0 (gchar, GEDIT_STDIN_BUFSIZE + 1);
-	g_return_val_if_fail (tmp_buf != NULL, FALSE);
+	case G_IO_STATUS_EOF:
+		{
+		/* EOF - End of communication on stdin. */
+		const GeditEncoding *encoding;
+		gchar *converted_text;
 
-	file_contents = g_string_new (NULL);
-	
-	while (feof (stdin) == 0)
-	{
-		buffer_length = fread (tmp_buf, 1, GEDIT_STDIN_BUFSIZE, stdin);
-		tmp_buf [buffer_length] = '\0';
-		g_string_append (file_contents, tmp_buf);
+		g_print ("eof\n");
+		g_print (contents->str);
 
-		if (ferror (stdin) != 0)
+		encoding = gedit_encoding_get_current ();
+
+		if (encoding == gedit_encoding_get_utf8 ())
 		{
-			res = gnome_vfs_result_from_errno (); 
+			if (g_utf8_validate (contents->str, total_len, NULL))
+			{
+				converted_text = contents->str;
+				contents->str = NULL;
+			}
+			else
+			{
+				converted_text = NULL;
+			}
+		}
+		else
+		{	
+			converted_text = gedit_convert_to_utf8 (contents->str,	total_len, &encoding, NULL);
+		}
+
+		if (converted_text)
+		{
+			stdin_data = converted_text;
+			converted_text = NULL;
+		}
+		g_string_free (contents, TRUE);
+		contents = NULL;
+		
+		/* Close G_IO_Channel */
+		g_io_channel_close(ioc);
 		
-			g_free (tmp_buf);
-			g_string_free (file_contents, TRUE);
-			return NULL;
+		/* Quit inner gtk_main() which is called in function
+		   gedit_utils_get_stdin() */
+		gtk_main_quit();
+		return FALSE;
 		}
-	}
 
-	fclose (stdin);
+	case G_IO_STATUS_ERROR:
+		/* Deal with error, close channel, etc. */
+		/* Close G_IO_Channel */
+		g_io_channel_close(ioc);
+		
+		/* Quit inner gtk_main() which is called in function
+		   gedit_utils_get_stdin() */
+		gtk_main_quit();
+		
+		g_error_free (error);
+		return FALSE;
+
+	default:
+		g_return_val_if_reached(FALSE);
+	}
+}
 
-	return g_string_free (file_contents, FALSE);
+gchar *
+gedit_utils_get_stdin (void)
+{
+	GIOChannel *channel;
+	gchar *data = NULL;
+	extern gchar *stdin_data;
+	gedit_debug (DEBUG_DOCUMENT, "");
+
+	/* Setup GIOChannel on stdin to read data from pipe */
+	channel = g_io_channel_unix_new (0);
+	g_io_channel_set_encoding (channel, NULL, NULL);
+	g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL);
+	
+	/* Add watch to read data whenever it arrives 
+	  gedit_handle_stdin function handles data present on pipe 
+	  assigns global variable stdin_data to point to the data */
+	g_io_add_watch (channel, G_IO_IN | G_IO_HUP |G_IO_PRI,
+			gedit_handle_stdin, data);
+
+	/*Read stdin until EOF */		
+	gtk_main();
+	return (data);
 }
 
 void 
