ARIX
February 25th, 2003, 01:21 AM
Hi guys,
I'm coding under Solaris and using
int system(const char *string)
function in my program. In man pages I've read that this function
returns -1 when it fails but when it fails in my program it doesn't return -1. When I assigned the return value of function to variable of type int and printed it, it was 256 (strange???). Below I've placed the code:
#define STR_SIZE 4096
. . . .
. . . .
char cmd[STR_SIZE] = {0};
sprintf(cmd, "cd %s; %s", path, dc_str);
if(system(cmd) == -1)
{
printf("Error executing %s", cmd);
}
else
{
. . . . .
. . . . .
}
The failure is taking place because I'm passing to "path" variable such value which doesn't exist, and during attemption to change directory system() fails.In this case by documentation it must return -1 value and my programm must print the Error message.
I'm coding under Solaris and using
int system(const char *string)
function in my program. In man pages I've read that this function
returns -1 when it fails but when it fails in my program it doesn't return -1. When I assigned the return value of function to variable of type int and printed it, it was 256 (strange???). Below I've placed the code:
#define STR_SIZE 4096
. . . .
. . . .
char cmd[STR_SIZE] = {0};
sprintf(cmd, "cd %s; %s", path, dc_str);
if(system(cmd) == -1)
{
printf("Error executing %s", cmd);
}
else
{
. . . . .
. . . . .
}
The failure is taking place because I'm passing to "path" variable such value which doesn't exist, and during attemption to change directory system() fails.In this case by documentation it must return -1 value and my programm must print the Error message.