2

I have a scripts (a.py) reads in 2 parameters like this:-

#!/usr/bin/env python

import sys
username = sys.argv[1]
password = sys.argv[2]

Problem is, when I call the script with some special characters:-

a.py   "Lionel"   "my*password"

It gives me this error:-

/swdev/tools/python/current/linux64/bin/python: No match.

Any workaround for this?

10
  • 4
    The quotes should stop the shell from trying to glob the *. What does a.py's shebang line look like, and is python actually installed at /swdev/tools/python/current/linux64/bin/python? Commented Aug 23, 2011 at 11:59
  • I also cannot reproduce, are you sure the error occurs when reading sys.argv? Commented Aug 23, 2011 at 12:03
  • 4
    Since shell commands may be logged and are viewable by all users on a machine, it's not a good idea to input passwords as command-line arguments. Commented Aug 23, 2011 at 12:13
  • 3
    Definitely unrelated to python, since python errors never look like that. The shebang (#!...) is probably the problem. Commented Aug 23, 2011 at 12:25
  • Editted the question, putting in the shebang line. Yupe. The python is definitely installed at /swdev/tools/python/current/linux64/bin/python Commented Aug 24, 2011 at 1:01

3 Answers 3

1

The problem is in the commands you're actually using, which are not the same as the commands you've shown us. Evidence: in Perl, the first two command-line arguments are $ARGV[0] and $ARGV[1] (the command name is $0). The Perl script you showed us wouldn't produce the output you showed us.

"No match" is a shell error message.

Copy-and-paste (don't re-type) the exact contents of your Python script, the exact command line you used to invoke it, and the exact output you got.

Some more things to watch out for:

You're invoking the script as a.py, which implies either that you're copying it to some directory in your $PATH, or that . is in your $PATH. If the latter, that's a bad idea; consider what happens if you cd info a directory that contains a (possibly malicious) command called ls. Putting . at the end of your $PATH is safer than putting it at the beginning, but I still recommend leaving it out altogether and using ./command to invoke commands in the current directory. In any case, for purposes of this exercise, please use ./a.py rather than a.py, just so we can be sure you're not picking up another a.py from elsewhere in your $PATH.

This is a long shot, but check whether you have any files in your current directory with a * character in their names. some_command asd*123 (without quotation marks) will fail if there are no matching files, but not if there happens to be a file whose name is literally "asd*123".

Another thing to try: change your Python script as follows:

#!/usr/bin/env python

print "before import sys"

import sys

print "after import sys"

username = sys.argv[1]
password = sys.argv[2]

This will tell you whether the shell is invoking your script at all.

Sign up to request clarification or add additional context in comments.

1 Comment

@lionel319: I see you've accepted my answer, but I still can't tell what the problem was. Can you elaborate?
0

That error comes from your shell, not from Python. Do you have a shopt -s failglob set in your .bashrc or somewhere?

6 Comments

I checked, and i don't find the statements in my .cshrc* or .bashrc either.
BTW, I can't reproduce this at all on my system. Works fine with the special character.
i'm guess it should be c-shell, since i can only find .cshrd* in my local.
Try this: type bash -i, get a new prompt, then try to run the script.
|
0

/swdev/tools/python/current/linux64/bin/python: No match.

I think the problem is that the python env is not set:

Does python run at all on your machine ?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.