Featured post
c - Win32 dispatch program and redirect stdout to file buffer problem? -
on wi32 trying start executable redirects filename (current date) e.g. same as:
someexecutable.exe > 20101220000000.txt
when windows cmd.exe works fine. when doing program shown below system seems ot either drop redirect if creates file and/or seems buffer large amount of data before flushing disk. can't change executable being run. program beeing executed writes stdout, remember can't change @ all. (the simplest way woud stdout = filehandle; sadly impossible me right now!)
(not required: program waits system() not required simplest way of detaching program being run via system() )
#include <stdio.h> #include <stdlib.h> #include <time.h> int main(int argc, char *argv[]) { char execstr[512]; char s[30]; size_t i; struct tm tim; time_t now; = time(null); tim = *(localtime(&now)); = strftime(s,30,"%y%m%d%h%m",&tim); sprintf(execstr,"someexecutable.exe > %s.txt",s); printf("executing: \"%s\"\n",execstr); system(execstr); exit(0); return 0; }
i don't see reason not work, if case you, 1 of alternative solution use popen , read pipe writing in desired file. here sample code printing on screen. can write file instead of screen/console per requirement.
#include <stdio.h> #include <stdlib.h> #include <time.h> int main(int argc, char *argv[]) { char execstr[512]; char s[30]; size_t i; struct tm tim; time_t now; char buf[128]; file *pipe; = time(null); tim = *(localtime(&now)); = strftime(s,30,"%y%m%d%h%m",&tim); #if 0 sprintf(execstr,"a.exe > %s.txt",s); printf("executing: \"%s\"\n",execstr); #endif /* #if 0 */ if( (pipe = _popen("a.exe", "rt")) == null ) exit( 1 ); while(!feof(pipe)) { if (fgets(buf, 128, pipe) != null ) printf(buf); /* write required file here */ } _pclose(pipe); return 0; }
- Get link
- X
- Other Apps
Comments
Post a Comment