Yonatan Amir
Yonatan Amir

Reputation: 85

Wrong use of execlp function

I tried to write C program in Unix environment that uses the execlp function. I am executing the tsort command (tsort gets a text file as a input).

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  ");
}

the error is :

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

What did I do wrong?

Upvotes: 0

Views: 77

Answers (1)

Siguza
Siguza

Reputation: 23850

Quoting 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.

You're not doing that. Try:

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

Upvotes: 2

Related Questions