Redirect another process' output to a stream
-
Hello, my application needs to redirect a process' output to a stream, just like Win32's .NET did via StartInfo.RedirectOutputStream, but this function is missing in CF. Is there another way (maybe via P/Invoke?) Greetings
You seem to be searching for a managed method for accomplishing your goal. Unfortunately I don't know if there is other managed ways to redirect standard I/O. What I can tell you is that the unmanaged Win32 API that redirects standard devices is the SetStdHandle Function[^]. Good Luck, -David Delaune
-
You seem to be searching for a managed method for accomplishing your goal. Unfortunately I don't know if there is other managed ways to redirect standard I/O. What I can tell you is that the unmanaged Win32 API that redirects standard devices is the SetStdHandle Function[^]. Good Luck, -David Delaune
-
Chaser92 wrote:
Which library contains the procedure in WinCE?
You have my apologies. I did not realize that you were asking about an embedded environment. Perhaps you are looking for SetStdioPathW[^] and GetStdioPathW[^]? You can possibly use CreatePipe to create alternate input/output handles which are also opened from inside your application giving you complete input/output control. I think it could work like this: 1.) Call CreatePipe and save the handle to newhandle variable. 2.) Spawn a thread which reads the pipe handle. 3.) Call GetStdioPathW and save the handle to the a saved_output_handle variable. 4.) Call SetStdioPathW(1,newhandle). 5.) Call CreateProcess and your child process will inherit the parent i/o handles. 6.) Call SetStdioPathW(1,saved_output_handle) so you restore your own standard io handle. I hope I made sense... if not just ask. Best Wishes, -David Delaune
-
Chaser92 wrote:
Which library contains the procedure in WinCE?
You have my apologies. I did not realize that you were asking about an embedded environment. Perhaps you are looking for SetStdioPathW[^] and GetStdioPathW[^]? You can possibly use CreatePipe to create alternate input/output handles which are also opened from inside your application giving you complete input/output control. I think it could work like this: 1.) Call CreatePipe and save the handle to newhandle variable. 2.) Spawn a thread which reads the pipe handle. 3.) Call GetStdioPathW and save the handle to the a saved_output_handle variable. 4.) Call SetStdioPathW(1,newhandle). 5.) Call CreateProcess and your child process will inherit the parent i/o handles. 6.) Call SetStdioPathW(1,saved_output_handle) so you restore your own standard io handle. I hope I made sense... if not just ask. Best Wishes, -David Delaune
-
I get it, but as I don't know much about unmanaged coding, could you tell me how does one read or write to a pipe? or maybe some kinda example Many thanks, you're saving my life ;) Best greetings
-
You can read/write to the pipe just like it is a file. Unmanaged code this would be the WriteFile Function[^]. Best Wishes, -David Delaune
Hi Randor, I want to redirect the output of another process too, but in Windows Mobile. SetStdioPathW seems to work only in Windows CE. Do you know a function like SetStdioPathW that work at Windows Mobile? Thanks in advance.