Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

getRuntime().exec("chmod 777 a file.txt") - does not do the intended task

843798Feb 16 2005 — edited Feb 16 2005
Hi,

I am trying to change the permissions of file (file name has spaces) using the Runtime.getRuntime().exec() method on AIX platform. My sample code is -

import java.io.*;

public class ChangeMode
{
public static void main(String[] args)
{
Process p = null;
String cmd = null;
cmd = "chmod " + "000" + " " + "a file.txt";
try
{
p = Runtime.getRuntime().exec( cmd );
p.waitFor();
}
catch( Exception e )
{
e.printStackTrace();
}
System.out.println("The exit value "+p.exitValue());
}
}

In this case - I am getting exitValue of 2.

But, the strange part is that - I am able to run the command
"chmod 000 a file.txt "
from the command prompt successfully.

Any ideas what does an exitValue of 2 means and where is this program getting failed.

Thanks!
~Saurabh
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 16 2005
Added on Feb 16 2005
2 comments
783 views