Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Batch Dateien öffnen

Empfohlene Antworten

Veröffentlicht

:confused: Hallo Leute,

ich habe ne Batch-Datei geschrieben die den Status von PC´s im Netzwerk anzeigt. Der Code dieser Batch sieht in etwa so aus:

onoff.bat

@ECHO OFF

ping -n 1 -w 50 soave | findstr "TTL=" >NUL

if %errorlevel%==0 echo Soave: online

if %errorlevel%==1 echo Soave: offline

Das funktioniert mittlerweile ganz gut. Doch jetzt kommt die nächste Stufe:

Nun will das ein JAVA-Programm auf diese Batch aufruft und anzeigt so das der Benutzer das Ergebnis in ruhe lesen kann(über klick auf nen Button soll die *.bat geöffnet werden) oder noch besser, dass diese JAVA das ergebnis irgendwie erkennt und dann im JAVA-Programm der PC-Status von soave angezeigt wird.

Wäre cool wenn jemand wüsste wie ich das machen kann. :confused:

Hi, so habe ich es damals gemacht:


Process procSPL4exe = Runtime.getRuntime().exec(strCommandLine);

			// get the errorline from spl4.exe

			// and deliver one to the Vector

InputStream InputStreamSPPexe = procSPL4exe.getErrorStream();

int nSPL4byteStream = InputStreamSPPexe.read();

String strErrorLine = new String("");

while (-1 != nSPL4byteStream) {

  String aChar = new Character((char) nSPL4byteStream).toString();

  if (10 == nSPL4byteStream) {

    vecOutput.add(strErrorLine);

    //nSPL4byteStream = InputStreamSPPexe.read();

    strErrorLine = "";

  } else {

    strErrorLine = strErrorLine + aChar;

  }

  nSPL4byteStream = InputStreamSPPexe.read();

}

Du musst den Datenstrom der zurückgeliefert wird über einen InputStream (bzw. Errorstream) einlesen und dann hast du das Ergebnis der Konsolen-Ausgabe in einem String, den du dann einfach weiter verarbeiten kannst.

  • Autor

Mein Programmcode sieht jetzt in etwa so aus:


import java.io.*;

public class CmdExec2

{

  String strCommandLine;

  public CmdExec2(String ln)

  {

    strCommandLine = ln;

  }


  public String CmdExec3()

  {

    Process procSPL4exe = Runtime.getRuntime().exec(strCommandLine);

    // get the errorline from spl4.exe

    // and deliver one to the Vector

    InputStream InputStreamSPPexe = procSPL4exe.getErrorStream();

    int nSPL4byteStream = InputStreamSPPexe.read();

    String strErrorLine = new String("");

    while (-1 != nSPL4byteStream)

    {

      String aChar = new Character((char) nSPL4byteStream).toString();

      if (10 == nSPL4byteStream)

      {

        vecOutput.add(strErrorLine);

        //nSPL4byteStream = InputStreamSPPexe.read();

        strErrorLine = "";

      }

      else

      {

        strErrorLine = strErrorLine + aChar;

      }

      nSPL4byteStream = InputStreamSPPexe.read();

    }

  }

}

jedoch erhalte ich beim Compilieren folgende Fehlermeldung:

CmdExec.java:23: cannot resolve symbol

symbol: variable vecOutput

location: class CmdExec2

vecOutput.add(strErrorLine)

^

Woran liegt das jetzt schon wieder wie kann ich es ändern? Für mich hört sich das an als wäre vecOutput nicht definiert und ich soll die Variable definieren aber als was?

//Code Tags hinzugefügt

Als Vector!

Und bitte benutz die Code Tags.

Peter

Das ist der Tag, den man benutzt um hier Code lesbar zu machen. Einfach wenn du deinen Text erstellst und etwas als Code markieren/lesbar machen willst den Button "#" drücken (in der erweiterten Erstellung eines Posts gleich neben dem Button "Antworten")

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.