1

I am currently creating a launcher (launcher.py) in Python 2.7 which can be used from GUI and terminal input. The launcher combines already eisting Software, that has its own GUI and its own terminal mode.

I added an OptionParser (option.py) to start the embedded tools (app.py) directly from the launcher.

App.py executes and is generating correct results, BUT terminal always throws following error:

Usage: launcher.py [options] arg1 arg2
launcher.py: error: no such option -i

here is the option.py file: (is imported as module to launcher.py)

def execute():      
    tapp_object = tapp.TALP()
    input_file = sys.argv[sys.argv.index('-input') + 1]
    tapp_object.run(gui=False, filename=input_file)    

class Options(OptionParser):
  
  usage = "Usage: %prog arg1 "
  parser = OptionParser(usage=usage)


  def tapp_batch(option, opt, value, parser):
      p = mp.Process(target=execute)
      p.start()
      p.join()

  parser.add_option('--tapp', 
                    '--tAPPLICATION', 
                    action="callback", 
                    callback=tapp_batch, 
                    help='''start APP from batch mode using: 
                        -launcher.py --tapp -input filename.yml
                        add filename.yml file containing''' )


i tried to do an dirty fix, calling a 'pass' function for flag -i but then it throws the same error for -n -->

Usage: launcher.py [options] arg1 arg2
launcher.py: error: no such option -n

reading full -input string. Why ? and how do I fix it. Please help.

  • it seems code runs it with many arguments and you will have to get all of them. And maybe first display `sys.argv` to see what arguments you get. – furas Aug 23 '22 at 14:04
  • if you would use [argparse](https://docs.python.org/3/library/argparse.html#module-argparse) then you could use this suggestion: [Python argparse ignore unrecognised arguments - Stack Overflow](https://stackoverflow.com/questions/12818146/python-argparse-ignore-unrecognised-arguments) and code `args, unknown = parser.parse_known_args()` – furas Aug 23 '22 at 14:28
  • Thanks. Displaying sys.argv did the trick. – pummeluff25 Sep 02 '22 at 09:55

0 Answers0