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

    Join Date
    Mar 2008
    Posts
    63
    Rep Power
    7

    Perl script comes out because of a command failure. How to overcome it?


    Hi,
    I've a command which installs android apks one after the other. These apks names are stored in a file. I'm accessing the text file and issuing the below commmand to install apks.
    <code>
    $t = new Net::Telnet (Timeout => undef);
    $username="sqa";
    $password="Tmie";
    $t->open("xxxx.xx.com");
    $t->login($username, $password);
    $req_apks = "re2.txt";
    open(F2, "<", "$req_apks") or die "Cannot open APK Filelist file:$!";
    my $req;

    while ($req = <F2>)
    {
    chomp;
    @b= $t->cmd("./adb install $req");
    print @b;
    sleep(3);
    print "\n";
    }
    </code>
    But the command "./adb install " is failing after 1 or 2 apks are installed. I've around 10 apks in the text file to be installed. Is there any way so that even if ./adb install commmand fails the script should continue without dying?

    Thanks,
    Sharath
    Last edited by ramki067; November 5th, 2013 at 01:28 AM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2011
    Posts
    46
    Rep Power
    57
    Think you need to set the errmode to "return" on the connection, the default is "die" which prints the error and dies.

    Set the mode using:

    Code:
    $t->errmode("return");

    You can then check if there has been an error after calling cmd() as per the docs:

    When mode is "return" then the method generating the error places an error message in the object and returns an undefined value in a scalar context and an empty list in list context. The error message may be obtained using errmsg().

    Originally Posted by ramki067
    Hi,
    I've a command which installs android apks one after the other. These apks names are stored in a file. I'm accessing the text file and issuing the below commmand to install apks.
    <code>
    $t = new Net::Telnet (Timeout => undef);
    $username="sqa";
    $password="Tmie";
    $t->open("xxxx.xx.com");
    $t->login($username, $password);
    $req_apks = "re2.txt";
    open(F2, "<", "$req_apks") or die "Cannot open APK Filelist file:$!";
    my $req;

    while ($req = <F2>)
    {
    chomp;
    @b= $t->cmd("./adb install $req");
    print @b;
    sleep(3);
    print "\n";
    }
    </code>
    But the command "./adb install " is failing after 1 or 2 apks are installed. I've around 10 apks in the text file to be installed. Is there any way so that even if ./adb install commmand fails the script should continue without dying?

    Thanks,
    Sharath

IMN logo majestic logo threadwatch logo seochat tools logo