gpt4 book ai didi

c - 无法在 Windows 8 上使用 MinGW 执行 execl()

转载 作者:可可西里 更新时间:2023-11-01 11:30:24 25 4
gpt4 key购买 nike

我有一个文件hello.exe,文件路径是D:\test\hello.exe,这是一个简单的hello world程序(测试ok)。

我还有一个程序proc.c,文件路径是D:\test\proc.c,代码如下:

#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
#include<process.h>
#include<errno.h>
#include<string.h>

main(int argc,char *argv[])
{
int ret;
ret=execl("D:\\test\\hello.exe","D:\\test\\hello.exe");
if(ret==-1)
printf("%d:\t%s",ret,errno);
}

程序挂起(windows 对话框显示程序已停止工作)!!!我什至尝试将 D:/test/hello.exe 作为 execl() 的参数,但同样...

我哪里错了???请有人为我提供正确的语法?请向我提供在 Windows 下使用 MinGW 的 process.h 各种功能的示例代码。 Web 教程链接也是可以接受的。

非常感谢!!!

最佳答案

你必须包含一个库,

#include<unistd.h>

因为它是在这个库中定义的所以如果你不包含它你会得到一个错误。并更正您的代码,因为您写的是“exec”而不是 execl。

int main()
{

execl("D:/test/hello","D:/test/hello",0);
return 0;
}

关于c - 无法在 Windows 8 上使用 MinGW 执行 execl(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21500889/

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