gpt4 book ai didi

C-execl() : can't execute file located in another directory

转载 作者:太空狗 更新时间:2023-10-29 11:22:36 26 4
gpt4 key购买 nike

我正在尝试使用我的程序 notify.c 执行位于另一个目录中的名为“helloworld”的二进制文件(从 source.c 编译而来)。这是我的文件所在的位置:

/home/morts/桌面/helloworld

/home/morts/Desktop/Homeworks/notify

我试过:

const char *cmd = "/home/morts/Desktop/helloworld";
execl(cmd, "LOL", NULL);
perror("execl()");
exit(EXIT_FAILURE);

但我得到:

execl(): Permission denied

如果 helloworld 位于 notify 的同一目录中,我会简单地放置“./helloworld”,但由于它们位于不同的目录中,我该如何解决这个问题?

感谢和问候。

最佳答案

如果你想通过execl不带任何参数执行路径/bin/test下的文件hello尝试以下操作:

execl("/bin/test/hello", "hello", (char*)NULL);

检查以下内容,否则您可能会遇到权限拒绝错误:

  1. 第一个参数必须是一个/path/your_file,没有任何空格
  2. 第二个参数必须是“your_file”,与第一个参数相同
  3. 最后一个参数必须是 (char*)NULL

关于C-execl() : can't execute file located in another directory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16037809/

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