Need help with pipes.

Need help with pipes.

Post by zaph » Sun, 11 Nov 2001 08:50:00



How can I pipe to AND from a command ? Using popen, I can only pipe to
OR from a process. How can I both read a command's stdout (the
command's output) and write to the command's stdin (the command's
input).
 
 
 

Need help with pipes.

Post by eric » Sun, 11 Nov 2001 13:51:04



> How can I pipe to AND from a command ? Using popen, I can only pipe to
> OR from a process. How can I both read a command's stdout (the
> command's output) and write to the command's stdin (the command's
> input).

open two pipes fork a child, dup2 the stdin and stdout to those pipes,
exec new  program

Eric

 
 
 

1. MVS Mainframer needs help on pipes and process arguments

I've been trying for a couple of days to figure out how to get the arguments
of a running process from within a C program. I came across some code on the
net that lead me to try this. Now I'm not sure why it doesn't work. I've
been able to ensure that there are no errors, but the flow of program
execution doesn't work like the original example lead me to believe it
would.....  I'm sure, I've used "dbx" to watch the program execute.....

Is the fgets() valid for pipes??? Anybody that can help????

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[])
{
   char line[133];
   char command[80];
   FILE *fp;

   strcpy(command, "ps -efo ""%p %P %a"" 2>/dev/null");

   fp = popen(command, "r");

/* file handle is assigned, no error */

   while (!feof(fp))  /* can use feof() on file handle fp */
   {
      /* execution continues */
      if (fgets(line, sizeof(line), fp) == 0) /* fgets() returns 0, line is
null */
      {
         /* execution falls into this code on first call */
         pclose(fp);
         return 0;
      }
      else
      {
         printf(">%s<\n",line);
      }
   }

2. system hangs while booting after e2fsck

3. Need help with pipes

4. Name that Penguin ProducT!

5. Help needed pipes and named pipes

6. filelock

7. dump pipe gzip pipe ssh pipe dd... blocksize?

8. Communicator 401b6 SUCKS

9. DOUBLE PIPE FAILS BUT SEPERATE PIPES WORK - HELP ME UNDERSTAND WHY

10. I need some help running one server from two pipes..

11. need to pipe a find or locate command into the rm command....PLEASE help!

12. help with stream pipes needed

13. need to pipe a find or locate command into the rm command....PLEASE help!