Pipes



I have a problem with pipes, i want to write a piece of code that close stdin and stdout
and creates a pipe instead. Now i want that maybe lpr would be connected over this pipe
with my program .... Ok this works fine but my question is now how can i get stdin and
stdout pipes back ?? So that printf comes to the screen again !
Here comes my code :

// Declarations

  rc = pipe (pfd);
  if (rc == -1)
    {
      g_error ("Could nor create pipe");
      exit (1);
    }
  rc = fork ();
  if (rc == -1)
    {
      g_error ("Can´t fork ()");
      exit (1);
    }
  else if (rc == 0)
    {
      close (0);  // Close StdInputt

      dup (pfd[0]);  // Copy the pipe to stdin

      close (pfd[0]);
      close (pfd[1]);
      if (!strcasecmp (gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (combo)->entry)), "default"))
      {
 
       gs_call[gs_arg++] = gtk_entry_get_text (GTK_ENTRY (entry));
 
 gs_call[gs_arg++] = 0;
      execvp (gs_call[0], gs_call);
      g_error ("exec funktion failed !");
      exit (1);
      }
      else
      {
      char * temp;
      temp = (char *) g_malloc0 (40);
      g_snprintf(temp,40,"-P%s",gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (combo)->entry)));
      gs_call[gs_arg++] = gtk_entry_get_text (GTK_ENTRY (entry));
      gs_call[gs_arg++] = temp;
      gs_call[gs_arg++] = 0;
      g_free (temp);
      execvp (gs_call[0], gs_call);
      g_error ("exec funktion failed !");
      exit (1);
      }
    }
  close(1);
  dup(pfd[1]);
  close(pfd[0]);
  close(pfd[1]);
 
  printf ("Lists ... \n");
  /* And some more printf´s coming here */

  close(1);
  gtk_widget_destroy (GTK_WIDGET (print_window));
}
_______________________________________________________
Greetings to all ....

 
Andreas Scherf
+-------------------------------------------+
I EMail   : scherfa@fh-trier.de             I  
I Homepage: http://www.fh-trier.de/~scherfa I
+-------------------------------------------+
 

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]