Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this messageBinny 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
Post Follow-up to this messageBinny 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
Post Follow-up to this messageBinny 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
Post Follow-up to this messageOn 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,
Post Follow-up to this messageBinny 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
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.