CreateProcess 函数出现问题!

发布于 2024-08-24 22:18:01 字数 553 浏览 4 评论 0原文

我有我的主应用程序,从我的主应用程序我将调用另一个 模块(第三方)在我的主应用程序中执行一个小操作,当我调用该模块时..它会处理特定时间(例如5秒)。在处理时,它会在命令窗口中显示进程以及一些信息..现在我的主应用程序等待被调用的模块完成其进程。现在我的问题是..如何隐藏此命令窗口而不干扰其进程..我尝试使用 createprocess 但它似乎不起作用...

例如:我的主应用程序是父进程,被调用的应用程序是子进程。父进程应该独立于子进程。

int main()
{
  execl("c:\\users\\rakesh\\Desktop\\calledapplication.exe","c:\\users\\rakesh\\Desktop    \\calledapplication.exe",0);


}

code in calledapplication
int main
{
  printf("Rakesh");
}

如果您运行第一个程序,请检查下面的示例,考虑上述内容...输出将出现在相同的位置 命令窗口(不应该是这样)...我希望主应用程序创建进程,但它不应该受到子进程的影响。

I have my main application ,from my main application I will be calling another
module(third party) to perform a small operation in my main application,when I call that module..it processes for a particular time say 5 sec.while its proccessing it shows the process in the commmand window with some information..now my main application waits until the called module finishes its process.Now my Question is..how to do I hide this command window without disturbing its process..I tried to use the createprocess but it seems to not work...

for example: my main application is the Parent process and the called application is child process..Parent process should be independent of the child process..check my example below

int main()
{
  execl("c:\\users\\rakesh\\Desktop\\calledapplication.exe","c:\\users\\rakesh\\Desktop    \\calledapplication.exe",0);


}

code in calledapplication
int main
{
  printf("Rakesh");
}

now considering the above if you run the first program...output would appear in the same
command window(It shouldnt be like that)...I want the main application to create the process but it should not be affected by child process.

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

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

发布评论

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

评论(3

执手闯天涯 2024-08-31 22:18:01

CreateProcessdwCreationFlags参数中传递CREATE_NO_WINDOW

Pass CREATE_NO_WINDOW in the dwCreationFlags parameter of CreateProcess.

送舟行 2024-08-31 22:18:01

您谈到了“命令窗口”,所以我认为子级是控制台应用程序。
在这种情况下,您可以在单独的控制台中创建进程,并可选择强制新控制台图标化或隐藏。
以下代码启动一个解释批处理文件 (mytest.bat) 的子进程。
我希望它能有所帮助。问候。

#include <windows.h>
#include <stdio.h>

int main(int argc, char **argv)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
BOOL rv = FALSE;
WCHAR cmdline[] = TEXT("cmd.exe /c mytest.bat");

    memset(&si,0,sizeof(si));
    si.cb = sizeof(si);
// Add this if you want to hide or minimize the console
    si.dwFlags = STARTF_USESHOWWINDOW;
    si.wShowWindow = SW_HIDE; //or SW_MINIMIZE
///////////////////////////////////////////////////////
    memset(&pi,0,sizeof(pi));
    rv = CreateProcess(NULL, cmdline, NULL, NULL,
                           FALSE, CREATE_NEW_CONSOLE,
                           NULL, NULL, &si, &pi);
    if (rv) {
        WaitForSingleObject(pi.hProcess, INFINITE);
                printf("Done! :)\n");
    }
        else {
                printf("Failed :(\n");

    }

        return rv ? 0 : 1;
}

You talked about a "command window", so I presume that the child is a console application.
In that case you can create the process in a separate conole and optionally force the new console to be iconified or hidden.
The following code launch a child process that interprets a batch file (mytest.bat).
I hope it can help. Regards.

#include <windows.h>
#include <stdio.h>

int main(int argc, char **argv)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
BOOL rv = FALSE;
WCHAR cmdline[] = TEXT("cmd.exe /c mytest.bat");

    memset(&si,0,sizeof(si));
    si.cb = sizeof(si);
// Add this if you want to hide or minimize the console
    si.dwFlags = STARTF_USESHOWWINDOW;
    si.wShowWindow = SW_HIDE; //or SW_MINIMIZE
///////////////////////////////////////////////////////
    memset(&pi,0,sizeof(pi));
    rv = CreateProcess(NULL, cmdline, NULL, NULL,
                           FALSE, CREATE_NEW_CONSOLE,
                           NULL, NULL, &si, &pi);
    if (rv) {
        WaitForSingleObject(pi.hProcess, INFINITE);
                printf("Done! :)\n");
    }
        else {
                printf("Failed :(\n");

    }

        return rv ? 0 : 1;
}
吖咩 2024-08-31 22:18:01

听起来您希望子进程的输出显示在单独的窗口中。如果是这样,您需要调用 CreateProcess 并向其传递 CREATE_NEW_CONSOLE 标志,而不是使用 exec*

It sounds like you want the child process's output to show up in a separate window. If so, you want to call CreateProcess and pass it the CREATE_NEW_CONSOLE flag, rather than using exec*.

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