I am trying to call a java jar program using python which works fine when i pass the input arguments as string, Now i need to pass dictionary as a input argument.
Here is the code:
Python:
class ExecuteKTR():
def GET(self,r):
web.header('Access-Control-Allow-Origin','*')
web.header('Access-Control-Allow-Credentials', 'true')
secToken = web.input().SecurityToken
Domain = web.input().Domain
fieldnames = ast.literal_eval(web.input().fieldnames)
authResult = Auth.GetSession(secToken,Domain)
if authResult.reason == "OK":
args = ['ktrjob.jar', 'arg1', 'arg2', 'argN'] # Any number of args to be passed to the jar file
result = jarWrapper(*args)
print result
elif authResult.reason == 'Unauthorized':
result = comm.format_response(False,authResult.reason,"Check the custom message",exception=None)
return result
def jarWrapper(*args):
process = Popen(['java', '-jar']+list(args), stdout=PIPE, stderr=PIPE)
ret = []
while process.poll() is None:
line = process.stdout.readline()
print line
if line != '' and line.endswith('\n'):
ret.append(line[:-1])
stdout, stderr = process.communicate()
ret += stdout.split('\n')
if stderr != '':
ret += stderr.split('\n')
ret.remove('')
return ret
Java:
String file = "";
if(args.length != 0)
{
file = args[0];
for ( int i=0;i<=args.length;i++)
{
System.out.print(args[i]);
}
}
I need to pass a dictionary as a parameter to the java application. Sample one is,
{DateTime:12/03/2016,DealerName:'Test'}