2 things

Jeff Sturm jsturm@sigma6.com
Mon Aug 2 11:00:00 GMT 1999


Tom Tromey wrote:
> Simon> Also, here's a (very poor!) patch for Runtime.exec() which
> Simon> takes into account a single level of quoting in a passed-in
> Simon> execution string. So you can call exec("find /tmp -name xxx
> Simon> -printf '%p %AH'") for example.
> 
> Perhaps we should just pass the string verbatim to sh and let it sort
> it out.  What does the JDK do?

The JDK does not use any command interpreter for Runtime.exec(),
unfortunately... so to get wildcard expansion for instance you have to
invoke the shell explicity, e.g.

  String[] args = {"/bin/sh", "-c", "echo *"};
  Process p = Runtime.getRuntime().exec(args);

which can't be done portably.

If you pass a string to the JDK's exec() it makes a simplistic attempt
to tokenize the arguments, probably using StringTokenizer or some
such... I'd question whether it observes quotes at all.

-- 
Jeff Sturm
jsturm@sigma6.com


More information about the Java mailing list