Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14
Hi friends, I want to use perl program in my shell script,so I write "/perl/bin/perl.exe a.pl",but when I run it,it returns"/perl/bin/perl.exe: cannot execute binary file" ,I wonder why it comes ...
  1. #1
    Just Joined!
    Join Date
    Nov 2007
    Posts
    7

    why does it say"/perl/bin/perl.exe: cannot execute binary file"?

    Hi friends,
    I want to use perl program in my shell script,so I write "/perl/bin/perl.exe a.pl",but when I run it,it returns"/perl/bin/perl.exe: cannot execute binary file"
    ,I wonder why it comes that.

  2. #2
    Linux Enthusiast
    Join Date
    Aug 2006
    Location
    Portsmouth, UK
    Posts
    539
    .exe is a microsoft thingy

    type
    Code:
    $ which perl
    The output of that command should tell you where your shell is looking for the perl interpreter.

    for example:

    Code:
    [xxx@### ~]$ which perl
    /usr/bin/perl
    RHCE #100-015-395
    Please don't PM me with questions as no reply may offend, that's what the forums are for.

  3. #3
    Linux Engineer Freston's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    1,047
    Welcome to the forums!
    Quote Originally Posted by littletransformer
    I want to use perl program in my shell script,so I write "/perl/bin/perl.exe a.pl"
    Shouldn't that have been /usr/bin/perl?

    Quote Originally Posted by littletransformer
    but when I run it,it returns"/perl/bin/perl.exe: cannot execute binary file"
    ,I wonder why it comes that.
    I'm a bit confused by the path and the .exe suffix. The .exe suffix doesn't mean anything in Gnu/Linux, rather it is used by a different popular OS.

    Because of the error you get and the perl.exe thing, I'm inclined to think you've installed a Windows version on your machine?

    You may want to enter: which perl
    This gives the full path to the executable you'll need to run... if installed of course. But most Linux systems have


    EDIT: matonb beat me to it
    Can't tell an OS by it's GUI

  4. #4
    Just Joined!
    Join Date
    Nov 2007
    Posts
    7

    Question It works,thanks for your help.

    I am a new user of linux, so I really appreciate your help.
    but I now meet a new problem,that is I have the perl program in the shell script,which receive two filenames as parameters.
    so I make it "/usr/bin/perl /perl/a.pl $afile $bfile",both of the two files just consist of some text and don't have any extension names,but it seems that the program doesn't receive the parameters ,besides,it returns
    "afile:cannot execute binary file
    bfile:cannot execute binary file ".
    So I feel really confused about the problem.

  5. #5
    Linux User
    Join Date
    Jun 2007
    Posts
    318
    It would help if you post the shell script and /perl/a.pl.

  6. #6
    Just Joined!
    Join Date
    Nov 2007
    Posts
    7

    Unhappy about the code

    the a.pl is like following:
    #! /usr/bin/perl

    if (@ARGV != 2) {
    my $help = << "end_of_help;";
    Usage: a.pl <afile> <bfile>
    end_of_help;
    print $help;
    exit;
    }

    my $afile = shift @ARGV;
    my $bfile = shift @ARGV;


    open A, "$afile" or die "error opening afile! $!\n";

    open B, "$afile" or die "error opening afile! $!\n";

    while($str1=<$afile>&&$str2=<$bfile>){

    $string=$string.$str1;
    $string=$string.$str2;

    }

    print $string;

    And the shell script is:
    i=1
    pbfile=""
    tbfile=""

    while test $i -lq 1000
    do
    if test $i -le 10
    then
    $bfile '/b/b_00'$i''
    $afile '/a/a_00'$i''

    elif test $i -lt 100
    then
    $bfile '/b/b_0$i'
    $afile '/a/a_0$i'

    elif test $i -lt 1000
    then
    $bfile '/b/b_$i'
    $afile '/a/a_$i'

    fi

    /usr/bin/perl /perl/bin/a.pl $afile $bfile

    ((i=$i+1))
    done

    I am really grateful for your help.

  7. #7
    Linux User
    Join Date
    Jun 2007
    Posts
    318
    Which shell are you using? I'm assuming bash so I corrected the errors so it would run in bash:

    Code:
    #!/bin/bash
    
    i=1
    pbfile=""
    tbfile=""
    
    while test $i -lt 1000
    do
    if test $i -lt 10
    then
    bfile="/b/b_00$i"
    afile="/a/a_00$i"
    
    elif test $i -lt 100
    then
    bfile="/b/b_0$i"
    afile="/a/a_0$i"
    
    elif test $i -lt 1000
    then
    bfile="/b/b_$i"
    afile="/a/a_$i"
    
    fi
    
    /usr/bin/perl ./a.pl $afile $bfile
    
    ((i=$i+1))
    done
    Compare it to you original script and you'll see the changes I made.

    There's a problem with your perl script but I'm not familiar with perl.

  8. #8
    Linux Enthusiast
    Join Date
    Aug 2006
    Location
    Portsmouth, UK
    Posts
    539
    Or you coud just do the following:

    Code:
    #!/bin/bash
    
    for i in $(seq -w 1 1 1000); do
      ./a.pl "/a/a_"$i "/b/b_"$i
    done;
    RHCE #100-015-395
    Please don't PM me with questions as no reply may offend, that's what the forums are for.

  9. #9
    Just Joined!
    Join Date
    Nov 2007
    Posts
    7

    Smile to vsemaska

    friend,thank you for your help.acutuallty I used bash to run the script, and with your help now it can almost work well ,but do you mean that I should define the value afile with" afile="/a/a_00$i" " without the '$' mark. I am really puzzled about it, how come it different from the usage of variable i.
    at the same time now I have a small problem left, that is whenever I run it ,it will return 'error open bfile! no such file or directory',do you have any ideas about that?
    besides,why do you think my perl program has some problems,can you make it a bit clear?

  10. #10
    Just Joined!
    Join Date
    Nov 2007
    Posts
    7

    Smile another problem

    now I think I get another problem when I try to export the output in my shell script,do you friends have any ideas how I can handle this?
    I am thinking of changing "/usr/bin/perl ./a.pl $afile $bfile"
    for "/usr/bin/perl ./a.pl $afile $bfile>>/output/output_$i",but it doesn't work.If I want to make the output in separate files,like a_1 and b_1's output to output_1,how can I manage it?
    thank you!

Page 1 of 2 1 2 LastLast

Posting Permissions

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