com.mizar.commons.io
Class SystemCommandExecutor

java.lang.Object
  extended by com.mizar.commons.io.SystemCommandExecutor

public class SystemCommandExecutor
extends java.lang.Object

This class can be used to execute a system command from a Java application. See the documentation for the public methods of this class for more information. Documentation for this class is available at this URL: http://devdaily.com/java/java-processbuilder-process-system-exec Copyright 2010 alvin j. alexander, devdaily.com. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser Public License for more details. You should have received a copy of the GNU Lesser Public License along with this program. If not, see <http://www.gnu.org/licenses/>. Please ee the following page for the LGPL license: http://www.gnu.org/licenses/lgpl.txt


Constructor Summary
SystemCommandExecutor(java.util.List<java.lang.String> commandInformation)
          Pass in the system command you want to run as a List of Strings, as shown here: List<String> commands = new ArrayList<String>(); commands.add("/sbin/ping"); commands.add("-c"); commands.add("5"); commands.add("www.google.com"); SystemCommandExecutor commandExecutor = new SystemCommandExecutor(commands); commandExecutor.executeCommand(); Note: I've removed the other constructor that was here to support executing the sudo command.
SystemCommandExecutor(java.lang.String command)
          Pass in the system command you want to run as Strings, as shown here: The method will prepend shell and shellArgs to commandInformation.
 
Method Summary
 int executeCommand()
           
 java.lang.String getAdminPassword()
           
 java.util.List<java.lang.String> getCommandInformation()
           
 java.lang.String getShell()
           
 java.lang.String getShellArgs()
           
 java.util.List<java.lang.String> getStandardErrorFromCommand()
          Get the standard error (stderr) from the command you just exec'd.
 java.util.List<java.lang.String> getStandardOutputFromCommand()
          Get the standard output (stdout) from the command you just exec'd.
static void main(java.lang.String[] args)
           
 void setAdminPassword(java.lang.String adminPassword)
           
 void setCommandInformation(java.util.List<java.lang.String> commandInformation)
           
 void setShell(java.lang.String shell)
           
 void setShellArgs(java.lang.String shellArgs)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SystemCommandExecutor

public SystemCommandExecutor(java.util.List<java.lang.String> commandInformation)
Pass in the system command you want to run as a List of Strings, as shown here: List<String> commands = new ArrayList<String>(); commands.add("/sbin/ping"); commands.add("-c"); commands.add("5"); commands.add("www.google.com"); SystemCommandExecutor commandExecutor = new SystemCommandExecutor(commands); commandExecutor.executeCommand(); Note: I've removed the other constructor that was here to support executing the sudo command. I'll add that back in when I get the sudo command working to the point where it won't hang when the given password is wrong.

Parameters:
commandInformation - The command you want to run.

SystemCommandExecutor

public SystemCommandExecutor(java.lang.String command)
Pass in the system command you want to run as Strings, as shown here: The method will prepend shell and shellArgs to commandInformation.

Parameters:
command - The command you want to run.
Method Detail

executeCommand

public int executeCommand()
                   throws java.io.IOException,
                          java.lang.InterruptedException
Throws:
java.io.IOException
java.lang.InterruptedException

getStandardOutputFromCommand

public java.util.List<java.lang.String> getStandardOutputFromCommand()
Get the standard output (stdout) from the command you just exec'd.


getStandardErrorFromCommand

public java.util.List<java.lang.String> getStandardErrorFromCommand()
Get the standard error (stderr) from the command you just exec'd.


setCommandInformation

public void setCommandInformation(java.util.List<java.lang.String> commandInformation)

getCommandInformation

public java.util.List<java.lang.String> getCommandInformation()

setShell

public void setShell(java.lang.String shell)

getShell

public java.lang.String getShell()

setShellArgs

public void setShellArgs(java.lang.String shellArgs)

getShellArgs

public java.lang.String getShellArgs()

setAdminPassword

public void setAdminPassword(java.lang.String adminPassword)

getAdminPassword

public java.lang.String getAdminPassword()

main

public static void main(java.lang.String[] args)