java - Commons exec looking for main class in environment variable value -



java - Commons exec looking for main class in environment variable value -

i'm trying launch script within java application using apache commons exec, , getting next error:

error: not find or load main class "-dappenv=te org.apache.commons.exec.executeexception: process exited error: 1 (exit value: 1) @ org.apache.commons.exec.defaultexecutor.executeinternal(defaultexecutor.java:402) @ org.apache.commons.exec.defaultexecutor.execute(defaultexecutor.java:164) @ testrunner.runtest(testrunner.java:37) @ testmain.main(testmain.java:6)

for next code:

string jopts = "java_opts=\"-dappenv=te -dsetinstance=true -dinstance=.01\""; string command = "/path/to/bin/script.sh -s argval"; seek { map<string, string> procenv = environmentutils.getprocenvironment(); environmentutils.addvariabletoenvironment(procenv, jopts); commandline cmdline = commandline.parse(command); defaultexecutor executor = new defaultexecutor(); executor.setworkingdirectory(new file("/path/to")); executor.execute(cmdline, procenv); } grab (exception e) { e.printstacktrace(); }

the error throwing me loop, because appears splitting quoted value environment variable , looking class name instead of running command environment variable. it's worth, next executes fine in bash:

java_opts="-dappenv=te -dsetinstance=true -dinstance=.01" /path/to/bin/script.sh -s argval

can offer insight why quoted value beingness split on whitespace, and/or why it's looking main class in value of java_opts? using environment map properly?

part of problem exec adding own quotes value of java_opts. without quotes around value, environment variable gets set fine:

string jopts = "java_opts=-dappenv=te -dsetinstance=true -dinstance=.01";

the command in wrong format. argument passed commandline.parse() should just name of programme run:

string command = "/path/to/bin/script.sh"; commandline cmdline = commandline.parse(command);

the remaining arguments need added addargument():

cmdline.addargument("-s"); cmdline.addargument("argval");

java environment-variables apache-commons-exec

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -