Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / December 2006

Tip: Looking for answers? Try searching our database.

Help with ProcessBuilder and Wildcard characters

Thread view: 
duff - 27 Dec 2006 06:48 GMT
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
Gordon Beaton - 27 Dec 2006 08:02 GMT
> 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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.