Class CmdThread

java.lang.Object
at.letto.basespringboot.cmd.CmdThread
All Implemented Interfaces:
Runnable

public class CmdThread extends Object implements Runnable
Objekt, das für jedes asynchron gestartete Kommando erzeugt wird.
  • Field Details

    • ID_COUNTER

      private static final AtomicLong ID_COUNTER
    • COMMAND_MARKER

      private static final Pattern COMMAND_MARKER
    • cmdMode

      protected final CmdThread.CmdMode cmdMode
    • id

      protected final long id
    • homedir

      protected final String homedir
    • cmd

      protected final String[] cmd
    • command

      protected final String command
    • thread

      protected final Thread thread
    • starttime

      protected final long starttime
    • startdate

      protected final Date startdate
    • charset

      protected String charset
    • stoptime

      protected long stoptime
    • threadStatus

      protected volatile ThreadStatus threadStatus
    • error

      protected volatile Throwable error
    • out

      private final Vector<Vector<String>> out
    • err

      private final Vector<Vector<String>> err
    • htmlOutput

      protected final Vector<String> htmlOutput
    • template

      protected String template
    • batchfile

      public volatile File batchfile
    • p

      protected volatile Process p
  • Constructor Details

  • Method Details

    • createThread

      public static CmdThread createThread(String homedir, String charset, String... cmd)
    • createThread

      public static CmdThread createThread(String homedir, String charset, CmdThread.CmdMode cmdMode, String... cmd)
    • createThreadMessage

      public static CmdThread createThreadMessage(String message)
    • backlink

      public CmdThread backlink(String backlink)
    • template

      public CmdThread template(String template)
    • start

      public void start()
    • htmlCmd

      public void htmlCmd(String cmd)
      Gibt ein Kommando blau und HTML-escaped aus.
    • htmlCmdPlain

      protected void htmlCmdPlain(String cmd)
      Gibt ein Kommando blau aus. Der Name wurde aus Kompatibilitätsgründen beibehalten.
    • htmlOut

      public void htmlOut(String text)
      Gibt eine normale Ausgabe HTML-escaped aus.
    • htmlOutPlain

      protected void htmlOutPlain(String text)
      Gibt eine normale Ausgabe aus. Der Name wurde aus Kompatibilitätsgründen beibehalten.
    • htmlErr

      public void htmlErr(String text)
      Gibt eine Fehlerausgabe rot und HTML-escaped aus.
    • htmlErrPlain

      protected void htmlErrPlain(String text)
      Gibt eine Fehlerausgabe rot aus. Der Name wurde aus Kompatibilitätsgründen beibehalten.
    • runCmd

      public final void runCmd(String... commands)
      Führt mehrere Kommandos aus.
    • isScriptMode

      private boolean isScriptMode()
    • runAsScript

      private void runAsScript(String[] commands)
    • createScriptFile

      private File createScriptFile(String[] commands) throws IOException
      Throws:
      IOException
    • resolveWorkingDirectoryForTempFile

      private Path resolveWorkingDirectoryForTempFile() throws IOException
      Throws:
      IOException
    • shellQuote

      private static String shellQuote(String value)
    • task

      public void task()
    • run

      public void run()
      Specified by:
      run in interface Runnable
    • getHtmlOutput

      public String getHtmlOutput()
    • systemcall

      public void systemcall(String cmd, String charset, Vector<String> out)
    • systemcall

      public void systemcall(String cmd, String charset, Vector<String> out, Vector<String> err)
      Führt ein Kommando aus und wartet auf dessen Beendigung.
    • buildProcessCommand

      private List<String> buildProcessCommand(String commandText) throws IOException
      Throws:
      IOException
    • parseCommandLine

      private static List<String> parseCommandLine(String commandText) throws IOException
      Zerlegt eine Kommandozeile in Programm und Argumente. Unterstützt einfache und doppelte Anführungszeichen sowie Backslash- Escaping. Shell-Operatoren wie |, >, && oder Variablenexpansion werden im NORMAL-Modus absichtlich nicht ausgewertet.
      Throws:
      IOException
    • executeProcess

      private void executeProcess(List<String> processCommand, String charsetName, Vector<String> out, Vector<String> err) throws IOException
      Throws:
      IOException
    • configureWorkingDirectory

      private void configureWorkingDirectory(ProcessBuilder processBuilder) throws IOException
      Throws:
      IOException
    • readStream

      private void readStream(InputStream inputStream, Charset charset, Vector<String> target, boolean errorStream)
    • resolveCharset

      private static Charset resolveCharset(String charsetName)
    • registerStartError

      private void registerStartError(String prefix, IOException ex, Vector<String> out, Vector<String> err)
    • deleteBatchFile

      private void deleteBatchFile()
    • stop

      public void stop()
    • getTimeInfoHTML

      public String getTimeInfoHTML()
    • isFinished

      public boolean isFinished()
    • getCmdDto

      public CmdDto getCmdDto()
    • lastOutputLine

      public String lastOutputLine(int lines)
    • wait

      public void wait(int seconds)
      Wartet die angegebene Anzahl Sekunden.
    • waitms

      public void waitms(int milliseconds)
      Wartet die angegebene Anzahl Millisekunden.