views:

36

answers:

1

Continuing from this question

With each system call, the function constructs a set of parameters and sends them off to another program that is just console-based. Is there a way I can make it so that no console window pops up for each call?

I've done a search but the ones that aren't a linker issue just aren't working for me. For instance, I tried the _execl call and System::Diagnostics::Process^ myProcess = gcnew System::Diagnostics::Process; but they aren't working.

The _execl will bring a console window up, scroll a bunch of stuff (from the program I called I guess), then close the my app and not even do what it was supposed to do. The System::Diagnostics::Process^ myProcess = gcnew System::Diagnostics::Process; doesn't seem to execute what I want either because the output folder that should contain files, contains nothing.

So I'm open for ideas.

+1  A: 

The CreateProcess API gives you the control you need. For example:

#include <windows.h>

using namespace System;

int main(array<System::String ^> ^args)
{
    STARTUPINFO         si;
    PROCESS_INFORMATION pi;
    TCHAR               cmdLine[MAX_PATH] = L"myOtherApp.exe -with -some -args";

    ::ZeroMemory(&si, sizeof(si));
    si.cb = sizeof(si);

    ::CreateProcess(NULL, cmdLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);

    Console::ReadLine();
    return 0;
}

With the CreateProcess flags set to 0 as above, the secondary app does not open its own console window, and writes its output to the parent's window. To silence the secondary app entirely, look at other CreateProcess flags, e.g. CREATE_NO_WINDOW.

Oren Trutner