Problem with "errno" (errno.h)

I execute a system command from my application by resetting the errno value to 0.
EX:
errno = EOK;
system(“ls /nodir”);
printf(“error %d %s”, errno, strerror(errno));

I always get the output as 0, No errors even if the directory /nodir is not
present.

Any idea why this behaviour??? Iam using QNX6.3, SP2.

system will only set errno if it fails to run the command, not if the command itself fails. Look at system documentation to extract the return value of the command.

so how do i get this errno? should i not use system().
I need to execute a few commands and check their error values as well.

You are in luck. QNX comes with build-in documentation, there is a nice page about system that explains it all.

We wouldn’t want QNX’s doc people’s works to go to waste would we?

rc = system( “ls /tmp” );
if( rc == -1 )
{
printf( “shell could not be run\n” );
}
else
{
printf( “result of running command is %d\n”, WEXITSTATUS( rc ));
}

There are a group of functions called “spawn*()” …

Thanks for the plug, Mario!