Boost logo

Boost Users :

Subject: [Boost-users] Executable wrapped into another one: how to pass streams instead of real files?
From: Alessandro Candini (candini_at_[hidden])
Date: 2011-06-21 08:13:10


I give you a simplified example to explain what I would like to do.
I have the following code, which I cannot modify (hello.cpp):

|#include <iostream>
#include <fstream>
using namespace std;

int main( int argc, char *argv[] )
{
     string line;
     ifstream f( argv[1] );

     while(!f.eof())
     {
         getline(f, line);
         cout << line << endl;
     }

     return 0;
}

Launch example:
||caneta_at_host ~ $ ./hello myfile.txt
1 - This is
2 - a test
3 - file.

I have a wrapper program which I need to modify:
||#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <iostream>
#include <fstream>
#include <sstream>

using namespace std;

int main ()
{
     int ret;

     ret = execl ("./hello", "./hello", "myfile.txt", (char *)0);

     return 0;
}|

In this way it works perfectly...but how can I modify it in order to use
a stream or a string inside the wrapper program, instead of using a file
name?
I would like to have something like:

|#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <iostream>
#include <fstream>
#include <sstream>

using namespace std;

int main ()
{
     int ret;
     ifstream inputFile;

     inputFile << "1 - This is" << endl;
     inputFile << "2 - a test" << endl;
     inputFile << "3 - file." << endl;

     ret = execl ("./hello", "./hello", inputFile, (char *)0);

     return 0;
}|

This last example, of course, doesn't work...how can I modify it in
order to make it work?
Remember that I cannot modify hello.cpp...

Can the Boost.iostreams help me?

Thanks in advance.

-- 
Alessandro Candini
MEEO S.r.l.
Via Saragat 9
I-44122 Ferrara, Italy
Tel: +39 0532 1861501
Fax: +39 0532 1861637
http://www.meeo.it
========================================
"ATTENZIONE:le informazioni contenute in questo messaggio sono
da considerarsi confidenziali ed il loro utilizzo è riservato unicamente
al destinatario sopra indicato. Chi dovesse ricevere questo messaggio
per errore è tenuto ad informare il mittente ed a rimuoverlo
definitivamente da ogni supporto elettronico o cartaceo."
"WARNING:This message contains confidential and/or proprietary
information which may be subject to privilege or immunity and which
is intended for use of its addressee only. Should you receive this
message in error, you are kindly requested to inform the sender and
to definitively remove it from any paper or electronic format."


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net