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 13:08:28 GMT
On 11 May 2011 12:42, Simon Courtenage <courtenage@gmail.com> wrote:
> Hi
>
> The -host etc. are command line arguments to the BrokerMain class that I'm
> trying to run in the child process.

Yes, I gathered that, but why quote the args?

> I think
> I've sorted it though by creating the command line as a string and then
> parsing it into a CommandLine object
> using CommandLine.parse().

That's fragile, and not recommended in general.

> I had assumed that the order in which
> addArgument is called determines the order in which
> the arguments are passed to on the command line, but perhaps this is not the
> case?

It should be.

What does cmd.toString() show?

Which version of Exec are you using?

Your code works fine for me using 1.1.

> Regards
>
> Simon
>
> On Wed, May 11, 2011 at 12:38 PM, sebb <sebbaz@gmail.com> wrote:
>
>> 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
>>
>>
>

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


Mime
View raw message