0
的內容我知道批次變量設置爲網站
set /p var=<some.txt
設置VAR到文本文件的內容。 但是我怎樣才能得到一個webressource的內容?
set /p var=<http://example.com/somefile.php
這就是它應該如何工作的。 PHP文件返回一些生成的文本。
的內容我知道批次變量設置爲網站
set /p var=<some.txt
設置VAR到文本文件的內容。 但是我怎樣才能得到一個webressource的內容?
set /p var=<http://example.com/somefile.php
這就是它應該如何工作的。 PHP文件返回一些生成的文本。
這是batch
只有答案,因爲它不需要第三方程序,VBS或任何其他的東西。
基本上你會從這樣的事情開始 - 你下載一個文件,將它設置爲一個變量並嘗試回顯它。
bitsadmin.exe /transfer "MyTask" "https://xkcd.com/1678/index.html" "%cd%\content.html"
set /p content=<content.html
echo %content%
好吧,不是那麼快。批量不喜歡,除非內容沒有特殊的東西,它可以解釋,所以你需要確保文件不包含批處理命令或任何可以解釋爲他們。
例如,如果你的文件包含<
,這是你會得到什麼,如果該文件的內容僅僅是<missing.txt
(即嘗試加載一個文件不存在的內容):
set /p nope=<file.txt
echo %nope% # warning
OR你需要躲避內容:
:: to make ! work (google what delayed expansion is)
setlocal enabledelayedexpansion
:: fetch a file from that url
bitsadmin.exe /transfer "MyTask" "https://xkcd.com/1678/index.html" "%cd%\content.html"
:: clear the variable if available
set "content="
:: load content from file
for /f "delims=" %%i in (content.html) do set content=!content!%%i
:: echo with escaping special characters, keywords, etc
:: the bracket is really important here :)
echo(!content!
:: disable expansion
endlocal