|
-
February 25th, 2003, 02:21 AM
#1
Problem with system() function.
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|