This is a multipart message in MIME format.
--
[ Picked text/plain from multipart/alternative ]
I'm trying to redirect the output of a server command to a file, but I'm
having problems.

I've come up with the following code (this code is within a ConCommand that
I have written):







                char cmd[2048];



                // clear out any pending commands first

                engine->ServerExecute();



                // save the old stdout

                int oldstdout = dup(1);

                // redirect stdout to rcon.txt if writable

                FILE *fp = fopen("rcon.txt", "w");

                if(fp)

                {

                                dup2(fileno(fp), 1);

                }

                // prepare the command

                Q_snprintf(cmd, sizeof(cmd), "%s\n", engine->Cmd_Args());

                // just some tests

                puts("Test:");

                Msg("Cooltest\n");

                // queue the command

                engine->ServerCommand(msg);

                // actually execute the command

                engine->ServerExecute();

                // more tests

                puts("posttest");

                Msg("coolposttest\n");

                // restore everything if we messed with anything

                if(fp)

                {

                                // flush to make sure text gets written to
file, not console

                                fflush(stdout);

                                fclose(fp);

                                // put stdout back

                                dup2(oldstdout, 1);

                                // and close the duplicate

                                close(oldstdout);

                                flushall();

                }









When this code executes a command on the server (cvarlist for example), no
output is written to the console but there is no relevant output in the
rcon.txt file either. The contents of the rcon.txt file are:

Test:

posttest



The tests using Msg() don't write to the file nor does the server command.
Nothing is written to the console either, so it looks like the output gets
lost somewhere. Why doesn't this work to redirect output of Msg()? I'm
testing this in Windows. I'd be surprised if it didn't work in Linux as well
since Linux seems to be more compliant with these sorts of things.



Does anybody have any ideas or recommendations?

--


_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please 
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders

Reply via email to