execl() 返回“无法打开或解析参数”错误

execl() returns `cannot open or parse argument` error

本文关键字:参数 错误 返回 execl      更新时间:2023-10-16

我有这段代码来运行一个使用 execl() 的程序,我收到这个错误:

Cannot open or parse ' arg 3'. 

而且,当我删除参数 3 时,我收到参数 2 的相同错误,知道吗?

我正在调试,显然第一次是_pid大于 0,为什么可能?

int down[2], up[2];
pipe(down);   // creates pipe - [0] is for reading, [1] for writing
pipe(up);
pid_t _pid = fork();
if (_pid < 0)
    exit(1);

if (_pid == 0)
{
    close(down[1]);
    close(up[0]);
    dup2(down[0], 0);
    dup2(up[1], 1);
    execl(cmd_line, cmd_line, "arg 1", "arg 2", "arg 3", NULL);
    _exit(1);
}

// the rest of this fn is executed by the parent only
close(down[0]);
close(up[1]);
_down = down[1];
_up = up[0];
_reader_thd = new Thread(reader_wrapper, this);

听起来更像是你正在执行的任何内容都无法打开或解析你的参数。