#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    57
    Rep Power
    4

    Check Returns From system


    How can I test the return value if the system built in function? I tried the following:

    Code:
    system 'command' or croak "Command failed";
    I croak every time even though the syscall is successful because I see the uotput in the console and got a return 0 when I checked the value of $CHILD_ERROR or $?.

    FYI, I have a working script and am working on best practices. I'm getting errors from Critic for ignoring the return values of built ins like system and CHDIR. Just trying to learn the best way to handle this.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,947
    Rep Power
    1225
    Have you read the documentation for the system function? It explains this issue and provides example for testing the return code.

    perldoc -f system

    A program's exit code, if the program was written to standards, will be 0 on success,
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Location
    spaceBAR Central
    Posts
    229
    Rep Power
    42
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Location
    spaceBAR Central
    Posts
    229
    Rep Power
    42
    ....
    Last edited by spacebar208; May 11th, 2013 at 05:46 PM. Reason: Incorrect post

IMN logo majestic logo threadwatch logo seochat tools logo