Redirect console from .Net application to C++ application launched by a service

0

I have a win32 application (call it wrapper) which, as part of its duties, launches another application (.net - call it child) and captures its output by redirecting the stdout of child to its own stdout.

This works fine from the console.

However, if wrapper is launched periodically by a .net windows service, wrapper runs just fine but child fails to run. There is no .Net stack trace in the windows event viewer and the process exit code returned from child is 0xC06D007E, which equates to "Unknown Software Exception."

If I replace child with a win32 application, it launches, but there seems to be an encoding mismatch because the output gets turned into a bunch of missing glyphs. But at least the application runs and returns exit code 0 in that case.

So I have two problems, here:

  1. Why can't I launch child (.net) from wrapper (win32), when called from a service (.net)?
  2. If child is a win32 application, why is the character encoding messed up when wrapper is called through the service but not when called directly on the console?

Here's a link to the wrapper application source code: http://pastebin.com/akgaR090

The source code of child is irrelevant, as a hello world application is sufficient to demonstrate the behavior.

The .net service is calling the wrapper application with this code: http://pastebin.com/k0DYMB1f

Child source code sufficient to replicate the issue:

public class Child
{
    public int Main(string[] args)
    {

    }
}
c#
c++
.net
winapi
windows-services
asked on Stack Overflow Feb 11, 2015 by dodexahedron • edited Feb 11, 2015 by dodexahedron

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0