在 system() 调用中隐藏控制台窗口

发布于 2024-09-04 10:55:15 字数 616 浏览 3 评论 0原文

继续这个问题

对于每个系统调用,该函数都会构造一组参数并将它们发送到另一个基于控制台的程序。有没有办法让每次调用都不会弹出控制台窗口?

我已经进行了搜索,但那些不是链接器问题的搜索对我来说不起作用。例如,我尝试了 _execl 调用和 System::Diagnostics::Process^ myProcess = gcnew System::Diagnostics::Process; 但它们不起作用。

_execl 将打开一个控制台窗口,滚动一堆内容(我猜是来自我调用的程序),然后关闭我的应用程序,甚至不执行它应该执行的操作。 System::Diagnostics::Process^ myProcess = gcnew System::Diagnostics::Process; 似乎也没有执行我想要的操作,因为应该包含文件的输出文件夹不包含任何内容。

所以我愿意接受想法。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

剩一世无双 2024-09-11 10:55:15

CreateProcess API 为您提供所需的控制。例如:

#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;
}

如果将 CreateProcess 标志设置为 0(如上所述),辅助应用程序不会打开自己的控制台窗口,而是将其输出写入父窗口。要完全静默辅助应用程序,请查看其他 CreateProcess 标志,例如 CREATE_NO_WINDOW。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文