View Single Post
  #1 (permalink)  
Old 08-07-2007, 09:01 PM
LordSM LordSM is offline
Member
 
Join Date: Aug 2007
Posts: 1
LordSM is on a distinguished road
Unable to execute command line command in java
I am trying to run a command to add a group name. It is executed in command prompt of Windows 2003/2000
Say this is the command I want to execute:
net localgroup LordSM /add
Here LordSM is the group name.

I wrote the following code but it does not seem to work. Please suggest.

String ABC=Value1TextField.getText();
Value2Label.setText("Value is now " + ABC);

// Above is to get value from a JText Field

// Below is the code to run command for adding a group name to a System.
String ExecutedCmd = "net localgroup " + ABC + "/add";
Process p = Runtime.getRuntime().exec(ExecutedCmd);
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));


// read the output from the command

System.out.println("Here is the standard output of the command:\n");
while ((s = stdInput.readLine()) != null)
{ System.out.println(s); }

// read any errors from the attempted command

System.out.println("Here is the standard error of the command (if any):\n");
while ((s = stdError.readLine()) != null)
{ System.out.println(s); }
Reply With Quote
Sponsored Links