Ya, it does. I'm thinking that somehow Msg() is bypassing write() or the stdout file descriptor or something.
Is there a different trick that rcon uses to redirect output? -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Greg Scott Sent: Friday, June 29, 2007 8:23 AM To: [email protected] Subject: Re: [hlcoders] Redirect server command output -- [ Picked text/plain from multipart/alternative ] Did you try stepping through it in debug mode to make sure it's passing all the checks correctly? On 6/29/07, Tony Paloma <[EMAIL PROTECTED]> wrote: > > 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 > > -- _______________________________________________ To unsubscribe, edit your list preferences, or view the list archives, please visit: http://list.valvesoftware.com/mailman/listinfo/hlcoders _______________________________________________ To unsubscribe, edit your list preferences, or view the list archives, please visit: http://list.valvesoftware.com/mailman/listinfo/hlcoders

