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

    Join Date
    Oct 2013
    Posts
    4
    Rep Power
    0

    Bad file descriptor


    Hi all,

    I am using Ubuntu, so Windows is not the problem !

    I am writing a script to get datas from a .cfg file, using "eval". The .cfg file exists, as I first got errors when it wasn't correct, but the "Bad file descriptor" is still there

    Here is my script :

    ------------------------------------------------------------------

    #!/usr/bin/env perl

    use strict;
    use warnings;

    our $MBIST_SELECT_BITNR;
    our $TRC3_MBIST_SELECT_START_BIT;

    our $TRC3_WEN_BIT;
    our $TRC3_STATUS_BITNR;
    our $TRC3_OVERALL_DONE_BIT;
    our $TRC3_OVERALL_FAIL_BIT;
    our $TRC3_REGADDR_START_BIT;
    our $TRC3_REGADDR_STOP_BIT;

    our $REG_CONFIG0_ADDR;
    our $REG_CONFIG1_ADDR;
    our $REG_MCONTROL_ADDR;
    our $REG_MSTATUS_ADDR;

    our $REG_MCONTROL_START_BIT;
    our $REG_MSTATUS_DONE_BIT;
    our $REG_MSTATUS_FAIL_BIT;
    our $REG_MSTATUS_SFAIL_BIT;
    our $REG_MCONTROL_RARINIT_BIT;

    sub get_values_from_cfg{

    eval `cat test.cfg`; die ("Problem : $!");
    print "trc2 = $TRC2_LENGTH\n";
    return;
    }

    print "TEST 1";
    get_values_from_cfg();
    print "TEST 2";

    ----------------------------------------------------------------------

    and my .cfg file :

    -----------------------------------------------------------------------


    # TRC3

    $TRC2_LENGTH = 90;
    $TRC3_LENGTH = 120;
    $MBIST_SELECT_BITNR= 90;
    $TRC3_MBIST_SELECT_START_BIT= 30;

    $TRC3_WEN_BIT= 21;
    $TRC3_STATUS_BITNR= 5;
    $TRC3_OVERALL_DONE_BIT= 1;
    $TRC3_OVERALL_FAIL_BIT= 2;
    $TRC3_REGADDR_START_BIT= 22;
    $TRC3_REGADDR_STOP_BIT= 29;

    $REG_CONFIG0_ADDR= 0;
    $REG_CONFIG1_ADDR= 1;
    $REG_MCONTROL_ADDR= 2;
    $REG_MSTATUS_ADDR= 3;

    $REG_MCONTROL_START_BIT= 0;
    $REG_MSTATUS_DONE_BIT= 0;
    $REG_MSTATUS_FAIL_BIT= 1;
    $REG_MSTATUS_SFAIL_BIT= 3;
    $REG_MCONTROL_RARINIT_BIT= 12;

    ---------------------------------------------------------------

    Does anyone have an idea to help me ? Please I'm getting mad...
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,940
    Rep Power
    1225
    I am writing a script to get datas from a .cfg file, using "eval".
    Why are you doing that?

    Perl has many ways to read/parse a config file without having to resort to using eval to execute a shell command.

    Your method of testing if that eval statement failed is completely wrong. You need to check the status of $@.

    Personally, I'd NEVER do this, but if that's what you want then do it this way.
    Code:
    eval `cat test.cfg`;
    die "Problem : $@" if $@;
    Why are you declaring your vars with 'our' instead of 'my'? Using 'our' is rarely the proper thing to do.

    Comments on this post

    • Laurent_R agrees : I entirely agree with everything Fishmonger says.
    • keath agrees
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    /dev/null
    Posts
    163
    Rep Power
    19
    Agree with FishMonger; if you want to execute shell commands from inside of perl, why not write the script in sh/bash/ksh. Moreover, perl has good file handling and excellent string processing capabilities. You would save a great deal of effort if you use the appropriate tools for your job.
  6. #4
  7. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,262
    Rep Power
    1810
    I agree with the previous comments that you could have a much better method of setting your script's configuration; including just having a module of parameters which wouldn't have to be eval'd at all.

    But addressing the reason why this code isn't running:

    I think the problem is here:

    Code:
    eval `cat test.cfg`; die ("Problem : $!");
    That's not a conditional statement. You have told the script it has to die with an error message.

    Try:

    Code:
    eval `cat test.cfg`; die $@ if $@;
    Edit: Now I see FishMonger already addressed this. I'll just leave my post as a reminder to myself to fully wake up before reading the forum.
    Last edited by keath; October 31st, 2013 at 07:12 AM.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    4
    Rep Power
    0
    Well thanks a lot for your help

    It works perfect now, so I thank all of you again.

IMN logo majestic logo threadwatch logo seochat tools logo