commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject Re: [EXEC] Problems with command-line arguments when starting Java process
Date Wed, 11 May 2011 11:38:16 GMT
On 11 May 2011 10:54, Simon Courtenage <courtenage@gmail.com> wrote:
> Hi,
>
> I'm using the Commons Exec library to write a class that starts up a number
> of processes that run another Java class.  The code run
> by each of these processes then act as peers in a P2P network. My code for
> starting these processes, in brief, looks like this:
>
>                CommandLine cmd = new CommandLine("java");
>                cmd.addArgument("-classpath");
>                cmd.addArgument(classpath);
>                cmd.addArgument("uk.ac.wmin.
> fel.BrokerMain");
>                cmd.addArgument("\"-host\"");
>                cmd.addArgument(thisnode.getHost());
>                cmd.addArgument("\"-port\"");
>                cmd.addArgument(Integer.toString(thisnode.getPort()));
>                cmd.addArgument("\"-id\"");
>                cmd.addArgument(Integer.toString(thisnode.getID()));
>                DefaultExecuteResultHandler rhandler = new
> DefaultExecuteResultHandler();
>                ExecuteWatchdog wdog = new ExecuteWatchdog(5000);
>                Executor executor = new DefaultExecutor();
>                executor.setWatchdog(wdog);
>                executor.execute(cmd, rhandler);
>
> where thisnode is an object that holds data about the hostname and port that
> the BrokerMain class will use to act as a server process.
> However, when I try to execute this, I get the following error:
>
>                Could not create the Java virtual machine.
>                Unrecognized option: -host
>
> Can anyone help?  It seems that the command line argument to the BrokerMain
> class is being seen as an argument to the Java interpreter, but I
> don't know how to overcome this problem.

Try printing the command line using cmd.toString(), and see how that
behaves in a command-shell.

Why are you quoting "-host" etc.?

> Thanks for any help,
>
> Simon
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message