Hi,
Can someone please post a code example of how to convert a string with
execution command to array of arguments for Runtime.exec? (since
Runtime.exec(String) parses the string with StringTokenizer, it won't
handle quoted arguments very well).
I've tried StreamTokenizer, but it doesn't handle quotes well: "c:\foo"
converts to "c:foo"
Thanx,
Ittay
Lisa - 30 Mar 2005 21:37 GMT
> Hi,
>
[quoted text clipped - 8 lines]
> Thanx,
> Ittay
try split
Alan Moore - 31 Mar 2005 02:05 GMT
>Can someone please post a code example of how to convert a string with
>execution command to array of arguments for Runtime.exec? (since
[quoted text clipped - 3 lines]
>I've tried StreamTokenizer, but it doesn't handle quotes well: "c:\foo"
>converts to "c:foo"
Assuming you're running at least JDK 1.4, a regex approach is probably
the easiest:
List parts = new ArrayList();
Pattern p = Pattern.compile("\".*?\"|\\S+");
Matcher m = p.matcher(cmdString);
while (m.find())
{
parts.add(m.group());
}
String[] cmdArray = (String[])parts.toArray();