Welcome to Dream.In.Code
Become a C++ Expert!

Join 150,077 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,757 people online right now. Registration is fast and FREE... Join Now!




Output to file

 
Reply to this topicStart new topic

Output to file

GigaRoc
1 Feb, 2008 - 05:56 PM
Post #1

New D.I.C Head
*

Joined: 16 Jan, 2008
Posts: 6

Because of circumstances this is harder then it you would think.
I need to output to a file a data-stream coming from both internal fprintf statements and method's provided by a class.

that's not the hard part
but the program runs continually and while it's running a perl program is accessing the output, formating it and printing the data to the screen. I would also love for the perl program to be able to write to the file also.

Basically i have everything working. but on longer events steams OS locks the LogFile( i think ). I get the error and the program terminates.

I tryed only opening the file once and jsut fflush ing it. but what happens is when the perl program opens the file the C++ program loose the link to the file.

this is the output look
gFile() checks tosee if a lockfile exists. When the lockfile is deleted the program self-terminates.

CODE

// get first event... note this times out turning event into a NULL so you need to check later before outputing
    struct inotify_event * event = inotifytools_next_event( 1 );

    // while the lock file exists
    while (gFile()) {
        // this checks to make sure event is valid and prints
        if (event) {
            logFile = fopen(LOG_PATH, "a+");
            if (logFile == NULL)
            {
                printf("gnoitfy:ERROR: LogFile Failed to Open. Terminating program\n");
                exit(-1);
            }
            gPrint(logFile, event);
            fclose(logFile);
        }
        // and get all corisponding events
        event = inotifytools_next_event( 1 );
    }


is there another way to do this?
can (instead of opining and closing can i re-link?)

the OS is Linux Kernel 2.6
the events can happen unto 30 times a second
User is offlineProfile CardPM
+Quote Post

Nayana
RE: Output To File
3 Feb, 2008 - 12:44 AM
Post #2

DIC Hawk - 나야나 नयन:
Group Icon

Joined: 14 Nov, 2007
Posts: 824



Thanked: 5 times
Dream Kudos: 175
My Contributions
You could always consider having PHP write to a different file. The C++ program could then read that, and merge the data itself.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 11:14PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month