Wednesday, 15 April 2015

c++ - DLL output to stderr doesn't work when redirected from parent -



c++ - DLL output to stderr doesn't work when redirected from parent -

i've redirected stdout , stderr in dll with:

dup2(fileno(myloghandle), fileno(stderr)); dup2(fileno(myloghandle), fileno(stdout));

which works fine when tested dll.

std::cout << "cout\n"; std::cerr << "cerr\n"; fprintf(stdout,"stdout\n"); fprintf(stderr,"stderr\n"); fputs("fputs stdout\n",stdout); fputs("fputs stderr\n",stderr); system("echo scheme stdout"); system("echo scheme stderr 1>&2");

gives next output in log file:

cout cerr stdout stderr fputs stdout fputs stderr scheme stdout scheme stderr

but when dll (opened loadlibrary) using stderr don't in log file.

do miss obvious?

that's exclusively reasonable. not redirecting standard handles of process, standard output , error devices of dll's runtime. other dll appear using own instance of runtime.

fundamentally doing wrong way. should redirect standard output , standard error @ process level, when create process.

c++ c windows dll stderr

No comments:

Post a Comment