thedeveloperinlondon
Programmer
using the following program i am trying to feed a certain external process with its input and take its output and store the whole output onto a variable. i am from a perl background, usually in perl we can use |s easily with filehandles. can anyone point out what i did wrong below?
// script to test piping IOs
#include <fstream>
using std::cout;
using std::cin;
using std::ios;
using std::fstream;
int main() {
char buffer[256];
fstream PipeProcess("| /script_that_takes_input_then_gives_output |", ios::in | ios:ut);
if (!PipeProcess) {
cerr << "file could not be opened." << endl;
exit(1);
}
cout << "my input to this script";
// read the output from the script
while (!PipeProcess.eof())
{
PipeProcess.getline(buffer,256);
cin << buffer;
}
return 0;
}
~
~
// script to test piping IOs
#include <fstream>
using std::cout;
using std::cin;
using std::ios;
using std::fstream;
int main() {
char buffer[256];
fstream PipeProcess("| /script_that_takes_input_then_gives_output |", ios::in | ios:ut);
if (!PipeProcess) {
cerr << "file could not be opened." << endl;
exit(1);
}
cout << "my input to this script";
// read the output from the script
while (!PipeProcess.eof())
{
PipeProcess.getline(buffer,256);
cin << buffer;
}
return 0;
}
~
~