This is the mail archive of the java-discuss@sourceware.cygnus.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: 2 things


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]