|
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); }
|