CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2002
    Location
    Yerevan, Armenia
    Posts
    78

    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.

  2. #2
    Join Date
    May 2000
    Location
    Phoenix, AZ [USA]
    Posts
    1,347
    system() doesn't return -1 in the event that the program you
    called fails; it returns -1 if the actual CALL to your program fails.

    I'm not sure if system() will return the program's actual return
    value; I don't think that it does on Windows, but it might. On your
    OS, you're obviously constrained by what it supports.

    --Paul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured