如何使用 _spawn 或 _exec 进行引导?
编写以下程序后,它似乎没有将参数传递给被调用的应用程序。在研究 _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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
argv 向量中的第一个参数通常是要启动的可执行文件的完全限定名称:
(来自 MSDN)
同样:
(MSDN)
The first argument in the
argv
vector is conventionally the fully qualified name of the executable to be started:(From MSDN)
Likewise:
(MSDN)