Hi The -host etc. are command line arguments to the BrokerMain class that I'm trying to run in the child process. 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(). 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?
Regards Simon On Wed, May 11, 2011 at 12:38 PM, sebb <[email protected]> wrote: > On 11 May 2011 10:54, Simon Courtenage <[email protected]> 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: [email protected] > For additional commands, e-mail: [email protected] > >
