c - 错误使用execlp函数

标签 c unix

我尝试在 Unix 环境下使用 execlp 函数编写 C 程序。我正在执行 tsort 命令(tsort 获取一个文本文件作为输入)。

void syserr(char * str)
{
    perror(str);
    exit(1);
}
int main()
{
    int inpfd;
    int pipeC[2];
    char buffer[4];
    execlp("tsort","tsort","t.txt");
    syserr("execlp  ");
}

错误是:

tsort: extra operand 'AWA\211\377AVI\211\366AUI\211\325ATL\215%\350\a '
Try 'tsort --help' for more information.

我做错了什么?

最佳答案

引用 the manual on execlp

[...] The list of arguments must be terminated by a NULL pointer, and, since these are variadic functions, this pointer must be cast (char *) NULL.

你没有这样做。尝试:

execlp("tsort","tsort","t.txt",(char*)NULL);

关于c - 错误使用execlp函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44217389/

相关文章:

c - 指向带有 malloc 表达式的结构的指针预期错误 C

c - 用宏包围一个函数

c - 移位不适用于变量声明赋值单行

C:如何使用while循环计算多位整数的位数?

unix - 如何从匹配文件 2 的文件 1 中提取内容并将它们按文件 2 的顺序排列

linux - sed 在两个模式之间提取文本,其中第二个模式可以是其中之一

linux - 如何检查特定进程是否开始运行以及何时停止

c - 如果我对嵌套循环使用相同的变量,时间复杂度是 n 的数量级或 n 的平方

java - 运行第一个 Hadoop(在 unix 上)程序(在 Windows 7 上)

c++ - 在 C++ 中显示图像及其元数据