Was ist das Windows-Analogon des Linux Watch-Befehls?

Ich suche nach einer Windows-Programm - / Skript - / Befehlszeilenfunktion, die wie das Linux-Programm watch funktioniert.

watch ruft regelmäßig ein anderes Programm/was auch immer auf und zeigt das Ergebnis an, das sich hervorragend eignet, um jede Sekunde eine Ausgabedatei oder ähnliches zu aktualisieren:

watch cat my-output.txt

Oder, kräftiger:

watch grep "fail" my-output.txt

Ich habe es in Cygwins Bibliothek gesucht, aber es scheint nicht vorhanden zu sein.

Author: Pops, 2010-09-21

15 answers

watch ist in Cygwin im procps - Paket verfügbar, wie hier aufgeführt (diese Informationen finden Sie über die Paketsuche auf der Website, hier). Ich glaube nicht, dass dieses Paket vom Standard-Cygwin-Setup installiert wird, aber es ist eines, das ich normalerweise bei Neuinstallationen auswähle, um den watch-Befehl verfügbar zu haben.

Der Speicherort von Tools in Paketen stimmt normalerweise mit Paketnamen in Linux-Distributionen überein (das Paket, das watch enthält, ist auch procps auf Debian und Ubuntu). Cygwin Paketsuchfunktion schlägt fehl, Informationen für / von Linux-Distributionen können Hinweise bieten.

 18
Author: David Spillett,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2010-09-21 12:22:31

Schreibe dein eigenes. Angenommen, die Datei watch.bat enthält: -

@ECHO OFF
:loop
  cls
  %*
  timeout /t 5 > NUL
goto loop

Und rufen Sie es über, zum Beispiel:

watch echo test

Gibt alle 5 Sekunden test zurück.

 58
Author: harrymc,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2017-12-13 19:34:06

Powershell hat den Befehl "while". Sie können es wie in Linux verwenden:

While (1) {your_command; sleep 5}

Linux-version:

While true; do your_command; sleep5; done

Andere:

While ($true) {netstat-an | findstr 23560; sleep 5; date}

 37
Author: Mikis,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2017-09-15 06:37:06

Ein generischer Windows-Befehl oneliner, um dies zu erreichen:

for /l %g in () do @( echo test & timeout /t 2 )

Ersetzen Sie "echo test" durch den Befehl, den Sie wiederholt ausführen möchten.

 18
Author: w1mb0r,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2017-01-10 09:29:32

Ich habe dieses kleine PowerShell-Modul geschrieben, um das zu tun, wonach Sie gesucht haben. Legen Sie es einfach in

C:\Users\[username]\Documents\WindowsPowerShell\Modules\Watch

Und führen Sie import-module watch in PowerShell aus.


# ---- BEGIN SCRIPT
# Author:       John Rizzo
# Created:      06/12/2014
# Last Updated: 06/12/2014
# Website:      http://www.johnrizzo.net

function Watch {
    [CmdletBinding(SupportsShouldProcess=$True,ConfirmImpact='High')]
    param (
        [Parameter(Mandatory=$False,
                   ValueFromPipeline=$True,
                   ValueFromPipelineByPropertyName=$True)]
        [int]$interval = 10,

        [Parameter(Mandatory=$True,
                   ValueFromPipeline=$True,
                   ValueFromPipelineByPropertyName=$True)]
        [string]$command
    )
    process {
        $cmd = [scriptblock]::Create($command);
        While($True) {
            cls;
            Write-Host "Command: " $command;
            $cmd.Invoke();
            sleep $interval;
        }
    }
}

Export-ModuleMember -function Watch

# --- END SCRIPT
 7
Author: johnrizzo1,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2014-06-12 20:51:37

So würde ich es in PowerShell machen:

while(1){ netstat -an|grep 1920;start-sleep -seconds 2;clear }

Die Bedingung while(1) ist äquivalent zu while true, Schleifen auf unbestimmte Zeit.

 7
Author: klaypigeon,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2016-02-02 14:18:22

Es ist eine PowerShell one Liner:

while ($true) { <your command here> | Out-Host; Sleep 5; Clear }
 7
Author: ErikW,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2019-04-30 15:12:20

Sie können auch eine Verzögerung mit dem PING-Befehl erstellen, zum Beispiel:

@echo off
:loop
  cls
  dir c:\temp
  REM 5000mS (5 sec) delay...
  ping 1.1.1.1 -n 1 -w 5000 >NUL
goto loop
 3
Author: Linker3000,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2010-09-21 11:56:38

Ich hatte das gleiche Problem, wenn ich die Dateigröße einer Datei überprüfen musste, an der ein anderer Prozess aktiv gearbeitet hat. Am Ende habe ich die Funktionalität von watch unter Windows geklont. Die kompilierte exe sowie die Quelle ist auf der Website verfügbar.

Uhr für Windows -

 2
Author: garrettg84,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2014-03-16 01:56:41

Ich habe einen Watch-Befehl für Windows namens llwatch erstellt.

Der Code befindet sich beide auf meiner Website landenlabs.com

Und auch auf GitHub

Möglicherweise müssen Sie x64 verwenden, um x64-Programme und x32 für die anderen zu sehen. Nicht sicher, wie wählerisch windows.

 1
Author: LanDenLabs,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2016-01-29 13:44:00

Was @harrymc außer mit Schlaf gesagt hat Uhr.Fledermaus -

@ECHO OFF
:loop
  %*
  sleep 5
goto loop

./Uhr.Fledermaus npm run test -

npm run test alle 5 Sekunden

 1
Author: user2167582,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2016-04-14 04:16:13
 0
Author: evandrix,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2018-05-23 16:36:01

Einige Verbesserungen am exzellenten PS-Modul von johnrizzo1 (siehe hier)

  • Umbenannte Funktion, die der Powershell-Namenskonvention entspricht (wie von duct_tape_coder vorgeschlagen)
  • Intervall in zweites Argument verschoben, daher optional; reduzierte Standardeinstellung auf 2 Sekunden
  • Rufen Sie zuerst die Ausgabe von Invoke ab und aktualisieren Sie dann den Bildschirm. Dadurch wird vermieden, dass der Bildschirm leer wird, während der Befehl
function Watch-Command {
    [CmdletBinding(SupportsShouldProcess=$True,ConfirmImpact='High')]
    param (
        [Parameter(Mandatory=$True,
                   ValueFromPipeline=$True,
                   ValueFromPipelineByPropertyName=$True)]
        [string]$command,

        [Parameter(Mandatory=$False,
                   ValueFromPipeline=$True,
                   ValueFromPipelineByPropertyName=$True)]
        [int]$interval = 2
    )
    process {
        $cmd = [scriptblock]::Create($command);
        While($True) {
            $output = $cmd.Invoke();
            cls;
            Write-Host "Command: " $command;
            Write-Host ($output | Out-String);
            sleep $interval;
        }
    }
}
 0
Author: Wesley,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2020-10-30 08:07:20

Ich hatte es eilig.... Ich habe einen Vorschlag verwendet und ihn ein wenig geändert, um für mich zu arbeiten:

For /l %g in () do @( echo test & timeout /t 2 )

Ich habe es geändert in:

For /l %g in () do @( test.bat & timeout /t 2 )

Und ich habe den Test erstellt.bat-Datei mit der Befehlszeile. In meinem Fall war es:

Netzgruppe / Domäne

Ich habe festgestellt, dass der Befehl echo gerade auf dem Bildschirm ausgedruckt wurde, aber den Befehl

 -1
Author: aguilae,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2018-08-10 13:42:34
while(1) { clear; Command ;sleep 3; }
 -1
Author: Hariharan S,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2020-12-18 09:33:10