What is this error?

Discussion in 'Perl Misc' started by Binny V A, Sep 28, 2004.

  1. Binny V A

    Binny V A Guest

    Hello Everyone,

    I have made many shell scripts using perl. Some of them are available
    at http://www.geocities.com/binnyva/code/perl/shell_scripts/index.html.
    When I user perl to create shell scripts, I get a error message that I
    don't understand.

    It appears when this code is used

    # Get a list of all matching files
    my $list;
    $list = `dir /b *.htm`;
    my @LIST = split(/\s+/, $list);

    This script shows the error...
    dir: /b: No such file or directory (ENOENT)

    Anyway the script works fine and does everything I would expect of it
    - except for showing the error. I just want to know what that error is
    and how to avoid it.

    Thank You,
    Binny V A.
    http://www.geocities.com/binnyva
    Binny V A, Sep 28, 2004
    #1
    1. Advertising

  2. Binny V A wrote:

    > # Get a list of all matching files
    > my $list;
    > $list = `dir /b *.htm`;
    > my @LIST = split(/\s+/, $list);
    >
    > This script shows the error...
    > dir: /b: No such file or directory (ENOENT)


    The "dir" command is often aliased to "ls -l" - that's a fairly common
    alias on UNIX systems, and the "-l" option gives the long-format listing
    similar to that produced by "dir" on DOS.

    But an alias is a simple beast; it does a simple text substitution, and
    doesn't know how to translate the "/b" switch to the correct "ls"
    option. So the result after the alias is expanded is "ls -l /b" - which
    attempts to list the contents of a non-existant directory /b.

    To correct the problem, use the UNIX "ls" command directly. Check the
    man page for ls to see what the option is that corresponds to the DOS
    "dir /b" option.

    This has *nothing* to do with Perl, by the way - you'd get precisely the
    same results calling "dir /b" from a bash, Python, or Ruby script, or a
    compiled C/C++ program.

    sherm--

    --
    Cocoa programming in Perl: http://camelbones.sourceforge.net
    Hire me! My resume: http://www.dot-app.org
    Sherm Pendley, Sep 28, 2004
    #2
    1. Advertising

  3. Binny V A wrote:
    >
    > When I user perl to create shell scripts, I get a error message that
    > I don't understand.


    If you get an error from _perl_ that you don't understand, look it up in
    the perldiag manpage. (Type "perldoc perldiag" at a command prompt.)

    > $list = `dir /b *.htm`;
    > [...]
    > dir: /b: No such file or directory (ENOENT)


    This is not a perl error, it's an error from the program that you're
    calling (dir). If you don't understand it, you should read the
    documentation (if any) for the program, or ask in a forum that discusses
    the program.

    At any rate, the error appears to be perfectly descriptive -- it's
    telling you that there are no files matching the provided pattern: *.htm

    > Anyway the script works fine and does everything I would expect of it
    > - except for showing the error. I just want to know what that error is
    > and how to avoid it.


    The reason the error isn't causing problems is that (as an error
    message) it's being printed on STDERR -- backticks only capture STDOUT.
    Maybe you should leave the error as-is. After all, it might be important
    to the user that no matching files were found. If you really want to
    suppress the error, you'll have to look up how to redirect STDERR for
    your shell. (This is not a perl issue.)

    For this particular case, the simple solution is to not go to the shell
    at all. You can get the file directly within Perl:

    my @LIST = glob('*.htm');

    See 'perldoc -f glob' (type it at a command prompt) for more information.

    -mjc
    Michael Carman, Sep 28, 2004
    #3
  4. Binny V A wrote:

    > Hello Everyone,
    >
    > I have made many shell scripts using perl. Some of them are available
    > at http://www.geocities.com/binnyva/code/perl/shell_scripts/index.html.
    > When I user perl to create shell scripts, I get a error message that I
    > don't understand.
    >
    > It appears when this code is used
    >
    > # Get a list of all matching files
    > my $list;
    > $list = `dir /b *.htm`;
    > my @LIST = split(/\s+/, $list);
    >
    > This script shows the error...
    > dir: /b: No such file or directory (ENOENT)


    :) The '/b' parameter is valid on MS-DOS but not on Linux or whatever
    is being used. Also, to list the directory contents use 'ls' over 'dir'

    In perl you can open a directory with 'opendir' and read the contents
    with 'readdir'.

    perldoc -f readdir

    B
    Brendon Caligari, Sep 28, 2004
    #4
  5. On 28 Sep 2004 12:19:29 -0700, (Binny V A) wrote:

    ># Get a list of all matching files
    >my $list;
    >$list = `dir /b *.htm`;
    >my @LIST = split(/\s+/, $list);


    Whatever you're trying to do, you shouldn't do it like this! You
    should use

    my @list = <*.htm>;

    instead.


    Michele
    --
    {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
    Michele Dondi, Sep 29, 2004
    #5
  6. Binny V A

    Joe Smith Guest

    Binny V A wrote:

    > $list = `dir /b *.htm`;
    > my @LIST = split(/\s+/, $list);
    >
    > This script shows the error...
    > dir: /b: No such file or directory (ENOENT)


    DIR is a built-in command in COMMAND.EXE or CMD.EXE on Windows.

    Some versions of perl for Windows have problems when using
    backticks on built-ins.

    Don't expect to run MS-DOS commands on Unix-type systems.

    linux% /usr/bin/dir /b *.htm
    /usr/bin/dir: /b: No such file or directory
    index.htm invite.htm

    linux% /usr/bin/dir -1 *.htm
    index.htm
    invite.htm

    -Joe
    Joe Smith, Sep 30, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hfk0
    Replies:
    2
    Views:
    21,656
  2. JavaQueries
    Replies:
    1
    Views:
    3,651
    John C. Bollinger
    Mar 1, 2005
  3. Balaji
    Replies:
    3
    Views:
    10,091
  4. Bishop
    Replies:
    1
    Views:
    771
    Bishop
    Feb 24, 2007
  5. juvi
    Replies:
    3
    Views:
    1,047
    Alexey Smirnov
    Jan 22, 2009
Loading...

Share This Page