如何使用 _spawn 或 _exec 进行引导?

发布于 2024-08-11 16:19:40 字数 723 浏览 5 评论 0原文

编写以下程序后,它似乎没有将参数传递给被调用的应用程序。在研究 _spawnv 及其功能时, _execvp 被发现为看起来的样子一个合适的替代方案。有谁在源代码中看到问题并知道需要做什么来解决它?

#include <stdio.h>
#include <stdlib.h>
#include <process.h>

int main(int argc, char** argv)
{
    int index;
    char** args;
    args = (char**) malloc((argc + 1) * sizeof(char*));
    args[0] = "boids.py";
    for (index = 1; index < argc; index++)
    {
        args[index - 1] = argv[index];
    }
    args[argc] = NULL;
    return _execvp("python", args);
}

After writing the following program, it does not appear to pass arguments to the called application. While researching _spawnv and what it can do, _execvp was found as what appeared to be a suitable alternative. Does anyone see the problem in the source code and know what needs to be done to fix it?

#include <stdio.h>
#include <stdlib.h>
#include <process.h>

int main(int argc, char** argv)
{
    int index;
    char** args;
    args = (char**) malloc((argc + 1) * sizeof(char*));
    args[0] = "boids.py";
    for (index = 1; index < argc; index++)
    {
        args[index - 1] = argv[index];
    }
    args[argc] = NULL;
    return _execvp("python", args);
}

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

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

发布评论

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

评论(1

失去的东西太少 2024-08-18 16:19:40

argv 向量中的第一个参数通常是要启动的可执行文件的完全限定名称:

_spawnv、_spawnve、_spawnvp 和
当参数数量可变时 _spawnvpe 调用很有用
新流程。指向的指针
参数作为数组传递,
argv。参数 argv[0] 通常是
指向实模式路径的指针或
保护模式下的程序名称,
和 argv1 通过 argv[n]是
指向字符串的指针
形成新的参数列表。这
参数 argv[n +1] 必须为 NULL
标记结束的指针
参数列表。

(来自 MSDN

同样:

_execv、_execve、_execvp 和
当参数数量为新时,_execvpe 调用很有用
过程是可变的。指向的指针
参数作为数组传递,
argv。参数argv[0]通常是
指向 cmdname 的指针。参数
argv1 到 argv[n] 点到
形成新的字符串
参数列表。参数
argv[n+1] 必须是指向的 NULL 指针
标记参数列表的末尾。

(MSDN)

The first argument in the argv vector is conventionally the fully qualified name of the executable to be started:

The _spawnv, _spawnve, _spawnvp, and
_spawnvpe calls are useful when there is a variable number of arguments to
the new process. Pointers to the
arguments are passed as an array,
argv. The argument argv[0] is usually
a pointer to a path in real mode or to
the program name in protected mode,
and argv1 through argv[n] are
pointers to the character strings
forming the new argument list. The
argument argv[n +1] must be a NULL
pointer to mark the end of the
argument list.

(From MSDN)

Likewise:

The _execv, _execve, _execvp, and
_execvpe calls are useful when the number of parameters to the new
process is variable. Pointers to the
parameters are passed as an array,
argv. The parameter argv[0] is usually
a pointer to cmdname. The parameters
argv1 through argv[n] point to the
character strings forming the new
parameter list. The parameter
argv[n+1] must be a NULL pointer to
mark the end of the parameter list.

(MSDN)

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