can't pass command-line arguments
Peter Hansen
peter at engcorp.com
Mon Apr 10 10:37:07 EDT 2006
BartlebyScrivener wrote:
> No conflicting bat file.
What about a conflicting non-BAT file? Anything in PATHEXT ahead of the
.PY extension is a candidate...
> if __name__ == "__main__":
> print sys.argv
> for path in all_files(sys.argv[1], sys.argv[2]):
> print path
>
> If I run
>
> cbfindfiles.py d:/ *emacs*
>
> from the command prompt I get:
>
> ['d:\\python\\cbfindfiles.py', 'd:/', '*emacs*']
> followed by a list of matching files
>
> If I run
>
> cbfindfiles d:/ *emacs*
>
> If get an empty command prompt back.
Then it's very likely not running this file... what if you put a print
at the very top of that file, saying just this:
print "running",__file__
If you don't see that, I think you have pretty good confirmation that it
is *not* in fact running that file.
> Oh, well.
>
> Not worth troubling over.
But it is. To help others. Perhaps what you are encountering is a real
bug, and solving it could avoid us having to deal with the same issue in
the future (though it seems more likely it's something special to your
case, but at least then we'll have a clear answer). Please reconsider
and investigate further.
If you run the following script and pass it the name "cbfindfiles", it
will print out a list of all files in the PATH that might be executed
when you type that name, in the order of the possible extensions in
PATHEXT. While you may be sure there's no .BAT file with that name,
maybe there is another with some other extension.
import sys
import os
name = sys.argv[1]
for dir in ['.'] + os.environ['PATH'].split(';'):
path = os.path.join(dir, name)
for ext in os.environ.get('PATHEXT', '').split(';'):
fullpath = path + ext
if os.path.isfile(fullpath):
print fullpath
-Peter
More information about the Python-list
mailing list