modify the program pipe1 cpp topipe1a cpp so that it accepts a command e g ls l from 5121699
Modify the program pipe1.cpp topipe1a.cpp so that it accepts a command (e.g. “ls-l”) from the keyboard. For example, when you execute “./pipe1a ps-auxw”, it should give you the same output aspipe1.cpp //pipe1.cpp
#include
#include
#include
#include
#include using namespace std; int main()
{
FILE *fpi; //for reading a pipe char buffer[BUFSIZ+1]; //BUFSIZ defined in int chars_read;
memset ( buffer, 0,sizeof(buffer)); //clear buffer
fpi = popen ( “ps -auxw”, “r” ); //pipe to command “ps -auxw”
if ( fpi != NULL ) {
//read data from pipe into buffer
chars_read = fread(buffer, sizeof(char), BUFSIZ,fpi );
if ( chars_read > 0 )
cout
pclose ( fpi ); //close the pipe
return 0;
} return 1;
} . . .