1

I am using one shell script to invoke the jython script. When I invoke shell script, I want to pass the arguments which should eventually get passed to jython script.
example command is as following

./passarg.sh -m 12345 -p 'hello'   

the passarg.sh code is as following.

#!/bin/bash
#check whether jython exist or not.
if  which jython >/dev/null; then
    echo " "
else
    echo "Jython does't exist on your system, install it first"
    echo "   Command: sudo apt-get install jython"
    exit 1
fi

# The dependent
export CLASSPATH=.:\
./lib/javaee.jar:\


jython myJythonscript.py  -a  #how to passed arguments to myJythonscript.py

Where as in the jython script I am using getopt to parse the arguments. The myJythonscript.py looks similar to as shown below.

#!/usr/bin/env jython

import unittest
import java
import time
import os
import sys, getopt
def authenticateAccount(verizionAmImp, mdn, password):
    if verizonAMImp.authenticateAccount(mdn, password):
        print mdn, " is registered"
    else:
         print mdn, " is not registered"    
def getRole(verizonAmImp, mdn):
     role = verizonAMImp.getRole(mdn)
     print mdn, " role is ", role

def main():
    URL = "http://localhost:8080/verizon-am-mock/ws/onlinedevice/service"

    password = "verizon0"
    methodCall = 0


    #for Debugging
    print " System Arguments ", sys.argv
    opts, operand = getopt(sys.argv[1:],"ar:m:p:u")

    for o,v in opts:
        if o == "-a":
            methodCall = 1
        elif o == "-r":
            methodCall = 2
        elif o == "-m":
            mdn = v
        elif o == "-p":
            password = v
        elif o == "-u":
            URL = v

    if (mdn is None) or (len(mdn) == 0):
        print "Please provide MDN in the argument"
        exit(1)       

    verizonAMImp = makePortFactory(URL);    

    if methodCall == 1:
        authenticateAccount(verizonAMImp, mdn, password)
    elif methodCall == 2 :    
        getRole(verizonAMImp, mdn)    
    else:
        print "Please check the arguments"
        exit(1) 
if __name__ == '__main__':
    main()

1 Answer 1

2

Same as always.

./someprog "$@"
Sign up to request clarification or add additional context in comments.

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.