gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 14:31:14 26 4
gpt4 key购买 nike

编写以下程序后,它似乎没有将参数传递给被调用的应用程序。研究时_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);
}

最佳答案

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

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.

(来自 MSDN )

同样:

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 )

关于c - 如何使用 _spawn 或 _exec 进行引导?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1780034/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com