Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...with companys cutting back on training, lack of true support by makers of software, the forums are a great tool in your cyber-toolbox...."

Geography

Where in the world do Tek-Tips members come from?

files and pipes and streams, oh my!Helpful Member! 

mbaranski (Programmer)
16 Mar 01 12:02
I'm trying to do 3 things:

1.  Open a pipe to "mysql -fs" and write to it using << operators:

I can't figure out how to use popen() and stuff to get an ostream out of that process.
i.e.
FILE *mysql;
mysql = popen("mysql -fs", "w");
/* Where to go now? */

2.  Open a file "carma.log" to write to using <<.  How do I do this?
FILE *logfile
logfile = fopen("carma.log", "w");
/* Now what?*/

3.  Re-direct stdout (I've got this down...)

any suggestions?
Thanks
MWB.



Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.

palbano (Programmer)
16 Mar 01 14:24
MWB,

I don't have current access to a UNIX box at the moment so I can only say that you need to create objects from the 'stream' library to perform '<< and >>' style IO.

There are old 'standard stream' libraries but the most current stream objects are in the STL.

Good luck
-pete
Helpful Member!  mbaranski (Programmer)
20 Mar 01 11:18
yeah, I just can't figure how to redirect a pipe opened, as in example 1, and then use the stream ops.  Also, in example 2...



Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.

classic773 (Programmer)
18 Jun 01 20:53
mbaranski, have you figured anything out with pipes?  I found pfstream.h is useful, however in my case, the author of a program i want to pipe from uses stderr instead of stderr.  Have you found any other ways to pipe, I'm looking for one. Thanks
ArnoMantwill (Programmer)
21 Jun 01 8:18
Here is a sample to work with a pipe. This sample looks, if a program is already running and returns the number of running programs.
But you can write as well to a pipe like to a file.

int send_emsgs_already_running ()
{
    FILE *fps;
    const char *ps = "ps -e|grep iaksend_emsgs";
    char pspid[10],    pstty[15], pstime[10], pscmd[300];
    int rc = 0;
    int frc = 0;
    
    fps = popen (ps, "r");
    if (fps == NULL)
    {
            Errorhandling...
            return -1;
    }
    while (frc != EOF)
    {
        strcpy ((char *)pscmd, "");
        frc = fscanf (fps, "%s %s %s %s", pspid, pstty, pstime, pscmd);
        if (strlen (pscmd))
        {
//            printf ("Found programs: %s %s %s \n", pspid, pstty, pstime, pscmd);
            if (! strcmp ((char *)pscmd, "iaksend_emsgs"))
            {
                rc += 1;
            }
        }
    }
    pclose (fps);
    return rc;
}



A link where you can find more information about pipes:
http://www.cs.cf.ac.uk/Dave/C/node23.html#SECTION002300000000000000000

Hope that helps    Arno

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close