I am trying to run a command under linux using ProcessBuilder. The
problem I am having is with wildcard character * not being interpreted
as it should be under normal linux command prompt.
example:
ProcessBuilder pb = new ProcessBuilder("/bin/chown", "-R",
"staff:staff", "*");
pb.redirectErrorStream(true);
Process p = pb.start();
...
It comes out with an error saying something along the lines of '*' is
not a file or cannot find the file etc.
So is there like an escape character to apply to *?
tia
> I am trying to run a command under linux using ProcessBuilder. The
> problem I am having is with wildcard character * not being
> interpreted as it should be under normal linux command prompt.
When you use ProcessBuilder or Runtime.exec() there is no command
shell to expand wildcards, so they are normal characters like any
other.
If you want a command shell to expand * for you, you need to include
one as part of the command, e.g.:
pb = new ProcessBuilder("/bin/sh",
"-c",
"/bin/chown -R staff:staff *");
/gordon

Signature
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
duff - 28 Dec 2006 23:25 GMT
>> I am trying to run a command under linux using ProcessBuilder. The
>> problem I am having is with wildcard character * not being
[quoted text clipped - 10 lines]
> "-c",
> "/bin/chown -R staff:staff *");
Thanks for the response. Tried it out and it works.
Just one question; what is the "-c" option for/means?
Lars Enderin - 29 Dec 2006 00:33 GMT
duff skrev:
>>> I am trying to run a command under linux using ProcessBuilder. The
>>> problem I am having is with wildcard character * not being
[quoted text clipped - 13 lines]
>
> Just one question; what is the "-c" option for/means?
The value of the -c option is the command to be executed by /bin/sh, i e
the next parameter.