On Apr 4, 12:38 pm, "oscartheduck" <[EMAIL PROTECTED]> wrote: > I have a small script for doing some ssh stuff for me. I could have > written it as shell script, but wanted to improve my python skills > some. > > RIght now, I'm not catching a syntax error as I'd like to. > > Here's my code: > > #!/usr/bin/env python > import sys > import os > > port = input("Please enter a port to connect on. If you're unsure or > just want the default of port 2024 just hit enter -- ") > > try: > if port > 65535: > print "That's not a valid port number, sorry. Between 0 and 65535 > is cool." > sys.exit() > else: > cmd = 'su root -c "/usr/sbin/sshd -p %s"' % port > except SyntaxError: > cmd = 'su root -c "/usr/sbin/sshd -p 2024;exit"' > > os.system(cmd) > > I'm under the impression that the except should catch the syntax error > and execute the "default" command, but hitting enter at the input > value doesn't lead to that. Any ideas what's going wrong?
Try sticking your port = input("Please enter a port to connect on. If you're unsure or just want the default of port 2024 just hit enter -- ") inside your "try" block instead. Or switch to using the "raw_input" builtin instead of "input". Mike -- http://mail.python.org/mailman/listinfo/python-list