2017-03-09 63 views
0

我希望能夠通過命令行有效「運行」每分鐘更新一次網站的URL。這是可能的,如果是這樣,我該怎麼做?在不通過CMD打開瀏覽器的情況下運行URL

我不希望這個命令打開瀏覽器,所以「開始」將不起作用。我只希望它每分鐘運行一次相同的URL。

+2

[wget的(https://en.wikipedia.org/wiki/Wget)或[捲曲](HTTPS://curl.haxx。 se /) – fvu

+0

這就是linux @fvu,你不能假設OP在其計算機 –

+1

@AP上有[** _ Cygwin _ **](http://cygwin.com/)。絕對不。 [curl以bazillion預編譯的二進制版本存在,包括沒有cygwin的windos](https://curl.haxx.se/download.html)。 [wget也是](http://gnuwin32.sourceforge.net/packages/wget.htm)。不要傳播錯誤信息。 – fvu

回答

0

如果您有Windows 7或更高版本,則可以在您的shell中訪問PowerShell。現在儘管使用命令工具如curlwget可能會有更高效的解決方案。你可以簡單地做在批處理文件如下:

:: Use the Out-Null under if you want to suppress output from server response 
echo Updating server... 
powershell -NoProfile "irm <YOUR_URL here> | Out-Null" 

一個完整的實現可能看起來像

@echo off 

:PingServer 
    echo Updating Server... 
    call powershell -NoProfile "irm <YOUR_URL here> | Out-Null" 
    ping localhost -n 60 -w 1000 > NUL 
goto PingServer 

注:平作爲second基於休眠機制,因爲timeout/sleep在所有的Windows環境中都不可用。

一個完整的PowerShell的做法可能是:

$URL = "<your url>" 

# Update the server, and additional processing if you'd want 
function Update-Server { 
    Write-Host "Updating the server..." 
    irm $URL | Out-Null 
} 

# While loop to update server, then sleep 1 minute 
while(1) {Update-Server;sleep 60} 
+0

你如何使這個循環運行 - 即每分鐘一次? – DSC

+0

新增實施 –

+0

@AP。以及爲什麼你使用ping進行計時? 「睡眠60」是本地的,並且會暫停批處理文件60秒。 – fvu

相關問題