Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to redirect console output to a file 2

Status
Not open for further replies.

rlev

Programmer
Feb 13, 2010
8
0
0
US
Hi Guys,

I spawn a child process using Createprocess API...this part is working fine but now I want to redirect the stderr output of the child process to a file....How I can do that?

My code snippet :


STARTUPINFO si;
PROCESS_INFORMATION pi;
memset(&pi, 0, sizeof(pi));
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;

si.wShowWindow = SW_NORMAL

int res = CreateProcessW(NULL, // Start the Process
PROCESS_PATH.c_str(),
NULL, NULL, NULL, NULL, NULL, NULL, &si,&pi);

if (res) {

// Do something
}


CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);



Any help would be apprecciate it.

Thank you
 
It's been a while since I've done this but try
Code:
PROCESS_PATH += " > ErrFile.txt";
 int res = CreateProcessW(NULL, PROCESS_PATH.c_str(), NULL, NULL, NULL, NULL, NULL, NULL, &si,&pi);

Thus if PROCESS_PATH was "C:\MyApp.exe", it would become "C:\MyApp.exe > ErrFile.txt" just like you had run it from the console.




James P. Cottingham
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
output redirection is a feature of cmd.exe, not of CreateProcessW. There are other ways of doing this (probably passing the right handles to CreateProcessW), but I'm not into C++, so can't tell you how, sorry.
 
Thank you Guys.

I will try both approaches and I will let you know if it works.

Rlev
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top