I have a Java bot that I'm working on which takes input from a user via an IRC message. The user types in something like .host file=foo file=bar hostname="this is a name" and it will start a server for them based on their input.
Right now I have a method that basically parses their message, looking for hostname="" (must be encapsulated by quotes), splitting the hostname= part, and setting the hostname to whatever their result is (for example, hostname="this is a name" would become -hostname 'this is a name'). I am using regex to do this.
I then split the string into an array (separated by spaces) and pass the information to processbuilder, which executes the command in it's own thread. The final command looks something like this:
./server -hostname "this is a name"
A problem I am running into is that since I am splitting by spaces, if the user adds a dash in the hostname (for example, hostname="this is - a name", it'll think that the dash is referring to an argument, and will basically chop off the rest.
Further explanation: processbuilder will split by spaces, so it will pass "-hostname" , "this" , "is" , "-" , "a" , "name". This is where I'm having trouble, since - means I should be passing an argument, but that's not what I am using it for.
What would be the most efficient way to implement this so that any character being passed is only literally this character? Should I not be splitting at spaces? If I run ./server -hostname "this is - a name" from the linux shell, it will run fine.
I appreciate any and all help. Thank you!