Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

What is this error?
Hello Everyone,

I have made many shell scripts using perl. Some of them are available
at http://www.geocities.com/binnyva/co...pts/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

Report this thread to moderator Post Follow-up to this message
Old Post
Binny V A
09-28-04 09:11 PM


Re: What is this error?
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

Report this thread to moderator Post Follow-up to this message
Old Post
Sherm Pendley
09-28-04 09:11 PM


Re: What is this error?
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

Report this thread to moderator Post Follow-up to this message
Old Post
Michael Carman
09-29-04 02:27 AM


Re: What is this error?
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/co...pts/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

Report this thread to moderator Post Follow-up to this message
Old Post
Brendon Caligari
09-29-04 02:27 AM


Re: What is this error?
On 28 Sep 2004 12:19:29 -0700, binnyva@hotmail.com (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{po
p^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,

Report this thread to moderator Post Follow-up to this message
Old Post
Michele Dondi
09-30-04 01:05 AM


Re: What is this error?
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

Report this thread to moderator Post Follow-up to this message
Old Post
Joe Smith
09-30-04 04:35 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Miscellaneous archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:35 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.