Results 1 to 2 of 2
- 08-07-2007, 08:01 PM #1
Member
- Join Date
- Aug 2007
- Posts
- 1
- Rep Power
- 0
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); }
- 08-08-2007, 01:23 AM #2
Senior Member
- Join Date
- Mar 2007
- Posts
- 134
- Rep Power
- 0
When Runtime.exec() won't - Java World
Read this It will definitly help then dont forget to destroy the process , In the worst case If you are not successfull put the command in a batch and call the batch file , Your code will not work because you are not specifying the process itslelf , you have to specify it as cmd.exe or some batch file
Similar Threads
-
Command line argument
By denisatandi in forum New To JavaReplies: 8Last Post: 10-17-2012, 12:37 AM -
Java command line
By agouzoul in forum New To JavaReplies: 2Last Post: 04-02-2008, 01:12 PM -
calling linux command line in java
By fangzhong in forum New To JavaReplies: 0Last Post: 02-03-2008, 05:24 PM -
Exporting from the command line
By o1121 in forum EclipseReplies: 1Last Post: 08-09-2007, 08:29 PM -
Java Command Line Arguments In Eclipse IDE
By JavaForums in forum EclipseReplies: 0Last Post: 05-19-2007, 10:45 AM
Bookmarks