I'm not able to execute shell command inside the perl script.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • omakhileshchand
    New Member
    • May 2012
    • 13

    I'm not able to execute shell command inside the perl script.

    This is a txt file
    cat msg0008.txt
    ;
    ; Message Information file
    ;
    [message]
    origmailbox=403 1
    context=Context _Test
    duration=10

    basically i want to cut 4031 from msg0008.txt

    There is piece of code in perl

    Code:
    foreach $file (@change_dir)
    {
            if (-d $file)
                    {
                     $file_dir = "/var/spool/asterisk/voicemail/default/$file/INBOX";
                     chdir("$file_dir");
                     $chek_wav = `find $file_dir -amin -3 -name "*.wav"|wc -l`;
                     system("cd");
    
             if($chek_wav != 0)
           {
    
    for($i=0;$i<=$chek_wav;$i++)
                    {
    
            @txt_format=`find /var/spool/asterisk/voicemail/default/$file/INBOX -amin -3 -name "*.txt"`;
    
            $txt_file=$txt_format[$i];
    
            $origmailbox=`sed -n '5p' $txt_format[$i]| cut -c 13-16`;
    
            print "$origmailbox\n" ;
    
                    }
    
            }
    
                    }
    }
    whenever i will execute this code i got error in following line

    $origmailbox=`s ed -n '5p' $txt_format[$i]| cut -c 13-16`;

    error :
    origmailbox=403 1
    sh: -c: line 1: syntax error near unexpected token `|'
    sh: -c: line 1: `| cut -c 13-16'
    512
  • RonB
    Recognized Expert Contributor
    • Jun 2009
    • 589

    #2
    Have you tried adding a space between the var and the pipe?

    Why all the backticks commands when Perl has its own methods of doing the same things without needing to fork sub processes?

    Comment

    Working...