By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,541 Members | 1,109 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,541 IT Pros & Developers. It's quick & easy.

Runtime and newgrp

P: n/a
Has anyone ran the Unix "newgrp" command from a java Runtime object? I
can't seem to get it to work the way it should.

Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"C. Allen Sher" <C_**********@yahoo.com> wrote in message
news:p7Wrb.17670$In3.2481@lakeread01...
Has anyone ran the Unix "newgrp" command from a java Runtime object? I
can't seem to get it to work the way it should.


Issuing *NIX and Linux command-line [i.e. shell] commands can be tricky,
particularly if multiple arguments and file redirection is involved.

Try:

String shell = "/bin/sh",
shellOpts = "/c",
cmd = "/bin/newchrp",
cmdArgs = "groupname > resultfile";

String[] command = { shell, shellOpts, cmd, cmdArgs };
Runtime.getRuntime().exec(command);

or maybe the less fancy:

String[] command =
{"/bin/sh", "-c", "/bin/newgrp groupname > resultfile"};

Runtime.getRuntime().exec(command);

I hope this helps.

Anthony Borla

Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.