Package core

Class ExternalCommand

java.lang.Object
core.ExternalCommand
All Implemented Interfaces:
Command

public class ExternalCommand extends Object implements Command
Represents an external (non-builtin) command to be executed via ProcessBuilder.
  • Constructor Details

    • ExternalCommand

      public ExternalCommand(List<String> args, File redirectFile)
      Constructs an ExternalCommand with arguments and optional redirection files.
      Parameters:
      args - The command and its arguments.
      redirectFile - Output redirection file, if any.
    • ExternalCommand

      public ExternalCommand(List<String> args, File redirectFile, File stderrRedirectFile)
      Constructs an ExternalCommand with arguments and optional redirection files for stdout and stderr.
      Parameters:
      args - The command and its arguments.
      redirectFile - Output redirection file, if any.
      stderrRedirectFile - Error redirection file, if any.
  • Method Details

    • execute

      public Path execute(String[] args, String rawInput, Path currentDirectory)
      Executes the external command and handles redirection.
      Specified by:
      execute in interface Command
      Parameters:
      args - The command and its arguments.
      rawInput - The raw input string.
      currentDirectory - The current working directory.
      Returns:
      The current directory (unchanged).
    • execute

      public void execute(File redirectFile, File stderrRedirectFile, boolean isAppend) throws IOException
      Executes the external command with specified redirection files and append mode.
      Parameters:
      redirectFile - Output redirection file, if any.
      stderrRedirectFile - Error redirection file, if any.
      isAppend - Whether to append to the output files.
      Throws:
      IOException - if an I/O error occurs.
    • getArgs

      public List<String> getArgs()
      Returns the arguments for the external command.
      Returns:
      The list of arguments.