|
@@ -7,6 +7,7 @@ package de.nplusc.izc.tools.baseTools;
|
|
|
//import java.util.logging.Logger;
|
|
|
//import org.apache.commons.io.*;
|
|
|
import de.nplusc.izc.tools.IOtools.FileTK;
|
|
|
+import de.nplusc.izc.tools.IOtools.PrintStreamCapturer;
|
|
|
import java.awt.Dimension;
|
|
|
import java.awt.GraphicsEnvironment;
|
|
|
import java.awt.HeadlessException;
|
|
@@ -19,6 +20,8 @@ import java.util.Map;
|
|
|
import java.util.Scanner;
|
|
|
import java.util.prefs.Preferences;
|
|
|
import javax.swing.*;
|
|
|
+import net.rubygrapefruit.platform.Native;
|
|
|
+import net.rubygrapefruit.platform.ProcessLauncher;
|
|
|
import org.apache.commons.exec.CommandLine;
|
|
|
import org.apache.commons.exec.DefaultExecuteResultHandler;
|
|
|
import org.apache.commons.exec.DefaultExecutor;
|
|
@@ -1693,67 +1696,51 @@ public class Tools
|
|
|
|
|
|
private static boolean sil = false;
|
|
|
|
|
|
- public static void runCmdWithOutToTextField(JTextArea txf, String... cmd)
|
|
|
+ public static boolean runCmdWithOutToTextField(JTextArea txf, String... cmd)
|
|
|
{
|
|
|
- runCmdStreamable(txf,new PrintStream(new NullOutputStream()),false, cmd);
|
|
|
+ return runCmdStreamable(txf,new PrintStream(new NullOutputStream()),false, cmd);
|
|
|
}
|
|
|
|
|
|
- public static void runCmdWithPassthru(PrintStream p,String... cmd)
|
|
|
+ public static boolean runCmdWithPassthru(PrintStream p,String... cmd)
|
|
|
{
|
|
|
- runCmdStreamable(new JTextArea(),p,false, cmd);
|
|
|
+ return runCmdStreamable(new JTextArea(),p,false, cmd);
|
|
|
}
|
|
|
|
|
|
- private static ExecuteStreamHandler s;
|
|
|
- private static JTextArea txf;
|
|
|
- private static PrintStream otherOut;
|
|
|
- public static void runCmdStreamable(JTextArea txf2,PrintStream otherOut2,final boolean SpamException, String... cmd)//synchronized gint nen fetten Bug
|
|
|
+ //private static ExecuteStreamHandler s;
|
|
|
+ //private static JTextArea txf;
|
|
|
+ //private static PrintStream otherOut;
|
|
|
+ public static boolean runCmdStreamable(JTextArea txf,PrintStream otherOut,final boolean SpamException, String... cmd)//synchronized gint nen fetten Bug
|
|
|
{
|
|
|
- txf=txf2;
|
|
|
- Tools.DebugHelperPrint(Arrays.toString(cmd), true, "Toolkit.enableFinerDebug");
|
|
|
- // BufferedInputStream log = new BufferedInputStream
|
|
|
- // (
|
|
|
- // new ByteArrayInputStream(new byte[]{0})
|
|
|
- // );//das einzelne Byte ist n(ö|ä)tig um ne NPX zu verhindern
|
|
|
-
|
|
|
- if(txf==null)
|
|
|
- {
|
|
|
- txf=new JTextArea();
|
|
|
- }
|
|
|
-
|
|
|
- if(otherOut==null)
|
|
|
- {
|
|
|
- otherOut=new PrintStream(new NullOutputStream());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- final DefaultExecuteResultHandler devnull = new DefaultExecuteResultHandler();
|
|
|
- /* {
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onProcessComplete(int exitValue)
|
|
|
- {
|
|
|
- System.err.println("fin");
|
|
|
- cmdGUI.sil=false;
|
|
|
- cmdGUI.cgui.setIsInCmd(false);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onProcessFailed(ExecuteException e)
|
|
|
- {
|
|
|
- System.err.println("Urrgs");
|
|
|
- cmdGUI.sil=false;
|
|
|
- cmdGUI.cgui.setIsInCmd(false);
|
|
|
- }
|
|
|
- };*/
|
|
|
- CommandLine cl = CommandLine.parse(cmd[0]);
|
|
|
- for (int i = 1; i < cmd.length; i++)
|
|
|
- {
|
|
|
+ try //synchronized gint nen fetten Bug
|
|
|
+ {
|
|
|
+ //txf=txf2;
|
|
|
+ Tools.DebugHelperPrint(Arrays.toString(cmd), true, "Toolkit.enableFinerDebug");
|
|
|
+ // BufferedInputStream log = new BufferedInputStream
|
|
|
+ // (
|
|
|
+ // new ByteArrayInputStream(new byte[]{0})
|
|
|
+ // );//das einzelne Byte ist n(ö|ä)tig um ne NPX zu verhindern
|
|
|
+
|
|
|
+ if(txf==null)
|
|
|
+ {
|
|
|
+ txf=new JTextArea();
|
|
|
+ }
|
|
|
+
|
|
|
+ if(otherOut==null)
|
|
|
+ {
|
|
|
+ otherOut=new PrintStream(new NullOutputStream());
|
|
|
+ }
|
|
|
+ // <editor-fold defaultstate="collapsed" desc="Altlast">
|
|
|
+ /*
|
|
|
+ final DefaultExecuteResultHandler devnull = new DefaultExecuteResultHandler();
|
|
|
+ CommandLine cl = CommandLine.parse(cmd[0]);
|
|
|
+ for (int i = 1; i < cmd.length; i++)
|
|
|
+ {
|
|
|
cl.addArgument(cmd[i]);
|
|
|
- }
|
|
|
- Executor e = new DefaultExecutor();
|
|
|
- //ex=(DefaultExecutor)e;
|
|
|
- try
|
|
|
- {
|
|
|
+ }
|
|
|
+ Executor e = new DefaultExecutor();
|
|
|
+ //ex=(DefaultExecutor)e;
|
|
|
+ try
|
|
|
+ {
|
|
|
final PipedInputStream in = new PipedInputStream();
|
|
|
PipedOutputStream out = new PipedOutputStream();
|
|
|
final PipedOutputStream txOut = new PipedOutputStream();
|
|
@@ -1761,219 +1748,159 @@ public class Tools
|
|
|
|
|
|
txIn.connect(txOut);
|
|
|
out.connect(in);
|
|
|
- // txOut.write((byte)0);//??//
|
|
|
- //System.err.pri
|
|
|
s = new PumpStreamHandler(out, out, txIn);
|
|
|
- //final OutputStream txOut = ((DefaultExecutor)e).stdin;
|
|
|
- // i.
|
|
|
-
|
|
|
- //s.setProcessOutputStream(log);
|
|
|
Tools.DebugHelperPrint("???", true, "Toolkit.enableFinerDebug");
|
|
|
e.setStreamHandler(s);
|
|
|
-
|
|
|
//^HAck da sonst zwodeitich//VOID
|
|
|
Tools.DebugHelperPrint("Wennhier was ist...", true, "Toolkit.enableFinerDebug");
|
|
|
-
|
|
|
- //log.
|
|
|
-
|
|
|
-
|
|
|
- //cG.
|
|
|
sil = true;;
|
|
|
- /*new Thread(new Runnable()
|
|
|
- {
|
|
|
- @Override
|
|
|
- @SuppressWarnings("SleepWhileInLoop")
|
|
|
- public void run()
|
|
|
- {
|
|
|
- // while(!devnull.hasResult())
|
|
|
- // {
|
|
|
- try
|
|
|
- {
|
|
|
- ex.p.waitFor();
|
|
|
- Thread.sleep(50);
|
|
|
- //System.err.println("AA");
|
|
|
- }
|
|
|
- catch (InterruptedException ex)
|
|
|
- {
|
|
|
- ex.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- //}
|
|
|
- System.err.println("fin");
|
|
|
- cmdGUI.sil=false;
|
|
|
- cmdGUI.cgui.setIsInCmd(false);
|
|
|
- System.err.println("Wr");
|
|
|
- System.setProperty("fin", "true");
|
|
|
- }
|
|
|
- }).start();*/
|
|
|
- new Thread(new Runnable()
|
|
|
+ new Thread(() ->
|
|
|
{
|
|
|
- //BufferedOutputStream txOut=(BufferedOutputStream)((DefaultExecutor)ex).getStdin();
|
|
|
- @Override
|
|
|
- @SuppressWarnings(
|
|
|
- {
|
|
|
- "SleepWhileInLoop", "SleepWhileInLoop"
|
|
|
- })
|
|
|
- public void run()
|
|
|
- {
|
|
|
- while (sil)
|
|
|
- {
|
|
|
- // try
|
|
|
- // {
|
|
|
- //txOut.write("x\b".getBytes());
|
|
|
- //txOut.flush();
|
|
|
- String chk = " ";
|
|
|
- // System.err.println(chk);
|
|
|
- Tools.DebugHelperPrint(chk, true, "ToolKit.enableStreamDataDebug");
|
|
|
- if (chk == null)
|
|
|
- {
|
|
|
- chk = "";
|
|
|
- }
|
|
|
- //if((!System.getProperty("fin", "lm").equals("lm")))
|
|
|
- //{
|
|
|
- // System.clearProperty("fin");
|
|
|
- // chk="\r";
|
|
|
- //}
|
|
|
- if (!chk.equals(""))
|
|
|
- {
|
|
|
-
|
|
|
- try
|
|
|
- {
|
|
|
- chk += "\n";
|
|
|
- //o=txOut
|
|
|
- txOut.write(chk.getBytes());
|
|
|
- txOut.flush();
|
|
|
- //System.err.println(">>"+chk);
|
|
|
- Tools.DebugHelperPrint(">>" + chk, true, "ToolKit.enableStreamDataDebug");
|
|
|
- //in.mark(1);
|
|
|
- //in.reset();Funzen nicht;
|
|
|
- }
|
|
|
- catch (IOException ex)
|
|
|
- {
|
|
|
- if(SpamException)
|
|
|
- ex.printStackTrace();
|
|
|
- if(ex.getMessage().contains("dead"))
|
|
|
- {
|
|
|
- sil=false;
|
|
|
- try
|
|
|
- {
|
|
|
- s.stop();
|
|
|
- }
|
|
|
- catch(IOException ex2)
|
|
|
- {
|
|
|
- ex2.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //cG.setCmdForSend(null,(int)t.get(0));//Nicht vergessen.sonst Bugschleuder
|
|
|
- chk = null;
|
|
|
-
|
|
|
- }
|
|
|
- Tools.wait(50);
|
|
|
-
|
|
|
- // }
|
|
|
- //catch (IOException ex)
|
|
|
- // {
|
|
|
- // System.err.println("Kakk");
|
|
|
- // ex.printStackTrace();
|
|
|
- // }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
+ while (sil)
|
|
|
+ {
|
|
|
+ String chk = " ";
|
|
|
+ Tools.DebugHelperPrint(chk, true, "ToolKit.enableStreamDataDebug");
|
|
|
+ if (!chk.equals(""))
|
|
|
+ {
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ chk += "\n";
|
|
|
+ //o=txOut
|
|
|
+ txOut.write(chk.getBytes());
|
|
|
+ txOut.flush();
|
|
|
+ Tools.DebugHelperPrint(">>" + chk, true, "ToolKit.enableStreamDataDebug");
|
|
|
+ }
|
|
|
+ catch (IOException ex)
|
|
|
+ {
|
|
|
+ if(SpamException)
|
|
|
+ ex.printStackTrace();
|
|
|
+ if(ex.getMessage().contains("dead"))
|
|
|
+ {
|
|
|
+ sil=false;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ s.stop();
|
|
|
+ }
|
|
|
+ catch(IOException ex2)
|
|
|
+ {
|
|
|
+ ex2.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ chk = null;
|
|
|
+ }
|
|
|
+ Tools.wait(50);
|
|
|
+ }
|
|
|
}).start();
|
|
|
- new Thread(new Runnable()
|
|
|
+ new Thread(() ->
|
|
|
{
|
|
|
- @Override
|
|
|
- public void run()
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- BufferedReader br = new BufferedReader(new InputStreamReader(in));
|
|
|
- //String s2 = br.readLine();
|
|
|
- //if(in.)
|
|
|
- while (sil)
|
|
|
- {
|
|
|
- while (in.available() > 0)//||(cmdGUI.sil))
|
|
|
- {
|
|
|
- byte rb = (byte) in.read();
|
|
|
- String ln = "" + (char) rb;
|
|
|
- //in.
|
|
|
- rb = (byte) in.read();
|
|
|
- Tools.DebugHelperPrint((char) rb + "|" + 0, true, "ToolKit.enableStreamDataDebug");
|
|
|
- int i = 0;
|
|
|
- while (((char) rb != '\n'))//&&((char)rb!='>'))
|
|
|
- {
|
|
|
- ln += (char) rb;
|
|
|
- // System.err.println((char)rb+"|"+i+1);
|
|
|
- Tools.DebugHelperPrint((char) rb + "|" + i + 1, true, "ToolKit.enableStreamDataDebug");
|
|
|
-
|
|
|
- rb = (byte) in.read();//DONOTFORGET!!!!!
|
|
|
- // System.err.println((char)rb+"|"+i+2);
|
|
|
- Tools.DebugHelperPrint((char) rb + "|" + i + 2, true, "ToolKit.enableStreamDataDebug");
|
|
|
-
|
|
|
- i++;
|
|
|
- }
|
|
|
- /*if((char)rb=='>')
|
|
|
- {
|
|
|
- ln+=">";
|
|
|
- }*/
|
|
|
- txf.append(ln + "\n");
|
|
|
- otherOut.println(ln);
|
|
|
- Tools.DebugHelperPrint(ln, true, "ToolKit.enableStreamDataDebug");
|
|
|
-
|
|
|
- //s2 = br.readLine();
|
|
|
- Tools.DebugHelperPrint("Fotze", true,"ToolKit.enableStreamDataDebug");
|
|
|
-
|
|
|
- }
|
|
|
- Tools.wait(50);
|
|
|
- }
|
|
|
- Tools.DebugHelperPrint("Hira?", true, "Toolkit.enableFinerDebug");
|
|
|
-
|
|
|
- }
|
|
|
- catch (IOException ex)
|
|
|
- {
|
|
|
- if(ex.getMessage().contains("dead"))
|
|
|
- {
|
|
|
- sil=false;
|
|
|
- try
|
|
|
- {
|
|
|
- s.stop();
|
|
|
- }
|
|
|
- catch(IOException ex2)
|
|
|
- {
|
|
|
- ex2.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- ex.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
+ try
|
|
|
+ {
|
|
|
+ BufferedReader br = new BufferedReader(new InputStreamReader(in));
|
|
|
+ while (sil)
|
|
|
+ {
|
|
|
+ while (in.available() > 0)//||(cmdGUI.sil))
|
|
|
+ {
|
|
|
+ byte rb = (byte) in.read();
|
|
|
+ String ln = "" + (char) rb;
|
|
|
+ //in.
|
|
|
+ rb = (byte) in.read();
|
|
|
+ Tools.DebugHelperPrint((char) rb + "|" + 0, true, "ToolKit.enableStreamDataDebug");
|
|
|
+ int i = 0;
|
|
|
+ while (((char) rb != '\n'))//&&((char)rb!='>'))
|
|
|
+ {
|
|
|
+ ln += (char) rb;
|
|
|
+ // System.err.println((char)rb+"|"+i+1);
|
|
|
+ Tools.DebugHelperPrint((char) rb + "|" + i + 1, true, "ToolKit.enableStreamDataDebug");
|
|
|
+
|
|
|
+ rb = (byte) in.read();//DONOTFORGET!!!!!
|
|
|
+ // System.err.println((char)rb+"|"+i+2);
|
|
|
+ Tools.DebugHelperPrint((char) rb + "|" + i + 2, true, "ToolKit.enableStreamDataDebug");
|
|
|
+
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ /*if((char)rb=='>')
|
|
|
+ {
|
|
|
+ ln+=">";
|
|
|
+ }* /
|
|
|
+ txf.append(ln + "\n");
|
|
|
+ otherOut.println(ln);
|
|
|
+ Tools.DebugHelperPrint(ln, true, "ToolKit.enableStreamDataDebug");
|
|
|
+
|
|
|
+ //s2 = br.readLine();
|
|
|
+ Tools.DebugHelperPrint("Fotze", true,"ToolKit.enableStreamDataDebug");
|
|
|
+
|
|
|
+ }
|
|
|
+ Tools.wait(50);
|
|
|
+ }
|
|
|
+ Tools.DebugHelperPrint("Hira?", true, "Toolkit.enableFinerDebug");
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (IOException ex)
|
|
|
+ {
|
|
|
+ if(ex.getMessage().contains("dead"))
|
|
|
+ {
|
|
|
+ sil=false;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ s.stop();
|
|
|
+ }
|
|
|
+ catch(IOException ex2)
|
|
|
+ {
|
|
|
+ ex2.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ex.printStackTrace();
|
|
|
+ }
|
|
|
}).start();
|
|
|
try
|
|
|
{
|
|
|
- e.execute(cl/*,devnull*/);//HACKALERT
|
|
|
+ e.execute(cl//,devnull
|
|
|
+ );//HACKALERT
|
|
|
}
|
|
|
catch (org.apache.commons.exec.ExecuteException exc)
|
|
|
{
|
|
|
- //Do nothing. Cmd steigt ja bei Error auch nicht aus
|
|
|
- //exc.printStackTrace();
|
|
|
+ //Do nothing. Cmd steigt ja bei Error auch nicht aus
|
|
|
+ //exc.printStackTrace();
|
|
|
}
|
|
|
Tools.DebugHelperPrint("fin", true, "Toolkit.enableFinerDebug");
|
|
|
|
|
|
sil = false;
|
|
|
-
|
|
|
- }
|
|
|
- catch (ExecuteException exc)
|
|
|
- {
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (ExecuteException exc)
|
|
|
+ {
|
|
|
exc.printStackTrace();
|
|
|
- }
|
|
|
- catch (IOException exc)
|
|
|
- {
|
|
|
+ }
|
|
|
+ catch (IOException exc)
|
|
|
+ {
|
|
|
if(SpamException)
|
|
|
exc.printStackTrace();
|
|
|
+ }
|
|
|
+ */
|
|
|
+ //</editor-fold>
|
|
|
+
|
|
|
+ System.out.println("OtherOut="+otherOut);
|
|
|
+
|
|
|
+ ProcessBuilder pb = new ProcessBuilder(Arrays.asList(cmd));
|
|
|
+ pb.redirectErrorStream(true);
|
|
|
+ ProcessLauncher l = Native.get(ProcessLauncher.class);
|
|
|
+ Process process = l.start(pb);
|
|
|
+ PrintStream stdout = new PrintStreamCapturer(txf, otherOut);
|
|
|
+ Thread stdoutThread = new Thread(new TextDumper(process.getInputStream(), stdout));
|
|
|
+ stdoutThread.start();
|
|
|
+ int result = process.waitFor();
|
|
|
+ stdoutThread.join();
|
|
|
+ Tools.DebugHelperPrint("FIN", true, "Toolkit.enableFinerDebug");
|
|
|
+ return result!=0;
|
|
|
+ //sil=false;
|
|
|
+ }
|
|
|
+ catch (InterruptedException ex)
|
|
|
+ {
|
|
|
+ ex.printStackTrace();
|
|
|
}
|
|
|
- Tools.DebugHelperPrint("FIN", true, "Toolkit.enableFinerDebug");
|
|
|
- //sil=false;
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -2035,6 +1962,46 @@ public class Tools
|
|
|
/* ... */
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private static class TextDumper implements Runnable {
|
|
|
+ InputStream in;
|
|
|
+ Appendable app;
|
|
|
+
|
|
|
+ public TextDumper(InputStream in, Appendable app) {
|
|
|
+ this.in = in;
|
|
|
+ this.app = app;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void run() {
|
|
|
+ InputStreamReader isr = new InputStreamReader(in);
|
|
|
+ BufferedReader br = new BufferedReader(isr);
|
|
|
+ String next;
|
|
|
+ try {
|
|
|
+ while ((next = br.readLine()) != null) {
|
|
|
+ if (app != null) {
|
|
|
+ app.append(next);
|
|
|
+ app.append("\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException("exception while reading process stream", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
private static int numEntered = 0, numMax = 0;
|
|
|
private static javax.swing.JButton btnAbbr;
|
|
|
private static javax.swing.JButton btnClear;
|