Results 1 to 4 of 4
  1. #1
    cooldharma06 is offline Member
    Join Date
    Aug 2013
    Posts
    1
    Rep Power
    0

    Cool how to run a superuser commands via java program.?

    hi all,
    i want to run the superuser commands via java program.

    Java Code:
    public static void main(String a[]) throws IOException
    	{
             try {
            	 Process p = Runtime.getRuntime().exec("ifconfig -a");
            	 BufferedReader in = new BufferedReader(
            	                                 new InputStreamReader(p.getInputStream()));
            	 String line = null;
            	 while ((line = in.readLine()) != null) {
            	                 System.out.println(line);
            	 }
            	 } catch (IOException e) {
            	 e.printStackTrace();
            	 }
    	}
    For normal commands like "ls" these things are working. but for super user commands its not working.
    i am running these things from IDE.
    Anybody know the way to solve this one.?!!

    Regards,
    cooldharma06.
    Last edited by cooldharma06; 08-29-2013 at 08:51 AM. Reason: Adding additional info

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,079
    Rep Power
    6

    Default Re: how to run a superuser commands via java program.?

    Question about Runtime.exec: check
    Code uses single String version: check
    Automated reply: When Runtime.exec() won't - JavaWorld
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,404
    Rep Power
    20

    Default Re: how to run a superuser commands via java program.?

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,079
    Rep Power
    6

    Default Re: how to run a superuser commands via java program.?

    luckily I didn't spend so much time to answer as Volodymyr Levytskyi did 2 hours before I did :/
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Running SVN commands through java program
    By testkiranpgp in forum New To Java
    Replies: 3
    Last Post: 04-13-2012, 12:41 PM
  2. java program for running the command prompt commands
    By leoanto in forum Advanced Java
    Replies: 2
    Last Post: 03-26-2011, 03:57 PM
  3. Replies: 25
    Last Post: 11-04-2010, 04:26 PM
  4. Need Help to Execute the commands from Java Program
    By Anjaneyulu in forum Advanced Java
    Replies: 7
    Last Post: 02-24-2010, 02:35 PM
  5. Execute the commands in Jsp Program
    By swetha_2008 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 12-17-2008, 06:04 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •