我试图在运行jar文件后检查Tomcat是否准备就绪。我在StackOverflow上找到了这个代码,我想编写Windows bash等效代码。
我的想法是登录文件并检查日志文件中的每个10个secondes,查看tomcat完成加载时出现的句子
这是我的代码:
@echo off
start javaw -jar ICAPS_DASHBOARD-0.1.0-SNAPSHOT.jar 1>> log.txt
::loop will be here
findstr /m "Started IcapsDashboardApplication" log.txt
if %errorlevel%==0 (
echo There is hope!
goto fin
)
echo no hope
:fin
echo fin
pause >nul
但我在日志文件中什么都没得到 如果我做的话
javaw -jar ICAPS_DASHBOARD-0.1.0-SNAPSHOT.jar 1>> log.txt
他不会在下面运行命令。
感谢
答案 0 :(得分:1)
你可以使用这个功能(据我所记得,积分去Tobias Weltner):
function Test-NetworkPort
{
param
(
$ComputerName = $env:COMPUTERNAME,
[int32[]]
[Parameter(ValueFromPipeline=$true)]
$Port = $(137..139 + 443 + 445),
[int32]
$Timeout=1000,
[switch]
$AllResults
)
process
{
$count = 0
ForEach ($PortNumber in $Port)
{
$count ++
$perc = $count * 100 / $Port.Count
Write-Progress -Activity "Scanning on \\$ComputerName" -Status "Port $PortNumber" -PercentComplete $perc
# in PowerShell 2.0 muss [Ordered] entfernt werden
# dann ist die Reihenfolge der Eigenschaften aber zufällig.
$result = New-Object PSObject -Property ([Ordered]@{
Port="$PortNumber"
Open=$False
Type='TCP'
ComputerName=$ComputerName
})
$TCPClient = New-Object System.Net.Sockets.TcpClient
$Connection = $TCPClient.BeginConnect($ComputerName, $PortNumber, $null, $null)
try
{
if ($Connection.AsyncWaitHandle.WaitOne($Timeout, $false))
{
$null = $TCPClient.EndConnect($Connection)
$result.Open = $true
}
}
catch {}
finally { $TCPClient.Close() }
$result | Where-Object { $AllResults -or $_.Open }
}
}
}
像Test-NetworkPort -Computername Tomcat1 -Port 80, 8080, 443 -Allresults
备注:如果使用Powershell 2,则需要在第24行删除[ordered
一词