[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Weird problem with function ls or system("ls...")
From: |
John W. Eaton |
Subject: |
Weird problem with function ls or system("ls...") |
Date: |
Tue, 28 Jul 2009 12:54:36 -0400 |
On 28-Jul-2009, Christian Weickhmann wrote:
| I stumbled over a weird problem using octave to read data from files.
|
| When I do an ls() or system("ls ...") in octave where no file matches my
search
| pattern, instead of returning an empty set, octave gives me a "No such file
or
| directory".
|
| Example:
|
| octave> mkdir test # create empty dir
| octave> ls
| # Works, no output
| ovtave> ls("*")
| # Works too, no output
That's not what I see. Instead, I see following error:
ls: cannot access *a*: No such file or directory
error: ls: command exited abnormally with status 2
error: called from:
error: /usr/share/octave/3.2.0/m/miscellaneous/ls.m at line 66, column 2
| octave> ls("*a*")
| ls: Zugriff auf *a* nicht möglich: No such file or directory
| error: ls: command exited abnormally with status 2
| error: called from:
| error: /usr/share/octave/3.2.0/m/miscellaneous/ls.m at line 66, column 2
|
| To be sure I looked into ls.m and found, that it's no magic at all: ls ->
| system("ls ..."). So i tried
|
| octave:> system("ls *a*")
| ls: Zugriff auf *a* nicht möglich: No such file or directory
| ans = 2
|
| I know, I can catch that with a try/catch block. So I would not directly call
| it a bug. But it's annoying. Frankly, it took me 1 hour to find what is
causing
| the problem. See, if you have a lot of data, and some record just doesn't
| exist, you might want him to continue just fine... ;)
|
| But it would be so much more intuitive, if worked just like in the ls * case,
| as bash's ls also gives you an empty set. I assume that this is not intended,
| because he obviously tries to access a file named "*a*".
There is no such thing as "bash's ls". The ls command is a separate
program, not a part of bash. And I'm not sure what you mean that it
also gives you an empty set. Here is what I see in an empty directory:
$ mkdir foo
$ cd foo
$ ls *
ls: cannot access *: No such file or directory
$ ls *a*
ls: cannot access *a*: No such file or directory
This is not surprising since Octave just uses system to invoke ls. So
the results should be the same.
FWIW, I think this behavior is also consistent with the way Matlab works.
Maybe you want to use dir instead of ls in your Octave program?
jwe
- Weird problem with function ls or system("ls..."), Christian Weickhmann, 2009/07/28
- Re: Weird problem with function ls or system("ls..."), Christian Weickhmann, 2009/07/28
- Re: Weird problem with function ls or system("ls..."), John W. Eaton, 2009/07/28
- Re: Weird problem with function ls or system("ls..."), David Grundberg, 2009/07/28
- Re: Weird problem with function ls or system("ls..."), Christian Weickhmann, 2009/07/28
- Re: Weird problem with function ls or system("ls..."), John W. Eaton, 2009/07/28
- Re: Weird problem with function ls or system("ls..."), Christian Weickhmann, 2009/07/28
- Re: Weird problem with function ls or system("ls..."), John W. Eaton, 2009/07/28
- Re: Weird problem with function ls or system("ls..."), Christian Weickhmann, 2009/07/28
- Re: Weird problem with function ls or system("ls..."), John W. Eaton, 2009/07/28