从批处理文件中读取文本文件,然后将文本传递给另一个函数(Reading a text file from a batch file, then passing text to another function)

希望有人能提供帮助。 我试过谷歌搜索这个网站,但我要么得到错误的关键字,否则我是第一个遇到这个问题的人(不太可能)。

我正在尝试从Windows批处理文件中的文本文件中读取域列表,我将在下面发布。 对于我正在尝试将结果写入文件的每一个。 我已经看过“for / f”的各种用法,但无法理解我需要做些什么来让线路工作。 这是代码:

@setlocal @echo off for /F "tokens=1" %%D in (c:\whois-for-win32\domainlist.txt) do call :reportit endlocal goto :eof :reportit setlocal echo " Retrieving details for: %%D" echo " WHOIS: %%D" >> c:\whois-for-win32\results\domainlisting.txt echo "=============================================================" >> c:\whois-for-win32\results\domainlisting.txt whois %%D >> c:\whois-for-win32\results\domainlisting.txt timeout 8 endlocal

现在,假设所引用的数据文件每行只列出一个域。 显然,我这样做的原因是我们需要检查相当多的域名。

感谢您的想法和想法!

Hope someone can help. I've tried by googling this site but I'm either getting the wrong keywords or else I'm the first person to come across this issue (unlikely).

I'm trying to read a list of domains from a text file in a Windows batch file, which I'll post below. For each of those I'm trying to write the results to a file. I've looked at various uses of the "for /f" but can't fathom out what I need to do to get the line to work. Here's the code:

@setlocal @echo off for /F "tokens=1" %%D in (c:\whois-for-win32\domainlist.txt) do call :reportit endlocal goto :eof :reportit setlocal echo " Retrieving details for: %%D" echo " WHOIS: %%D" >> c:\whois-for-win32\results\domainlisting.txt echo "=============================================================" >> c:\whois-for-win32\results\domainlisting.txt whois %%D >> c:\whois-for-win32\results\domainlisting.txt timeout 8 endlocal

Now, assume the data file referred to has only one domain listed per line. Obviously the reason I'm doing this is that we've got a rather large number of domains to check.

Your thoughts and ideas all gratefully received!

最满意答案

如果使用FOR-Loops,则参数仅在for循环的上下文中可见。 在您的函数中,它不能作为%% D访问。

但你可以通过调用参数传递它们, 在这种情况下,我使用“%%〜D”,因为%% ~D删除封闭引号(如果有的话),然后我将其括在引号中以确保内容仅作为一个参数传递。

在函数中,传递的参数可以通过%1访问,但要删除引号,我使用%~1。

@echo off setlocal for /F "tokens=* EOL=# delims=" %%D in (c:\whois-for-win32\domainlist.txt) do call :reportit "%%~D" endlocal goto :eof :reportit setlocal set "domain=%~1" echo " Retrieving details for: %domain%" echo " WHOIS: %domain%" >> c:\whois-for-win32\results\domainlisting.txt echo "=============================================================" >> c:\whois-for-win32\results\domainlisting.txt whois %domain% >> c:\whois-for-win32\results\domainlisting.txt timeout 8 endlocal exit /b

If you use FOR-Loops the parameter is only visible in the context of the for-loop. In your function it's not accessible as %%D.

But you could pass them with the call as parameter, in this case I use "%%~D", as %%~D removes enclosing quotes if there are some and then i enclose it into quotes to ensure that the content will deliver as only one parameter.

In the function the passed parameter can be accessed via %1, but to remove the quotes I use %~1.

@echo off setlocal for /F "tokens=* EOL=# delims=" %%D in (c:\whois-for-win32\domainlist.txt) do call :reportit "%%~D" endlocal goto :eof :reportit setlocal set "domain=%~1" echo " Retrieving details for: %domain%" echo " WHOIS: %domain%" >> c:\whois-for-win32\results\domainlisting.txt echo "=============================================================" >> c:\whois-for-win32\results\domainlisting.txt whois %domain% >> c:\whois-for-win32\results\domainlisting.txt timeout 8 endlocal exit /b从批处理文件中读取文本文件,然后将文本传递给另一个函数(Reading a text file from a batch file, then passing text to another function)

希望有人能提供帮助。 我试过谷歌搜索这个网站,但我要么得到错误的关键字,否则我是第一个遇到这个问题的人(不太可能)。

我正在尝试从Windows批处理文件中的文本文件中读取域列表,我将在下面发布。 对于我正在尝试将结果写入文件的每一个。 我已经看过“for / f”的各种用法,但无法理解我需要做些什么来让线路工作。 这是代码:

@setlocal @echo off for /F "tokens=1" %%D in (c:\whois-for-win32\domainlist.txt) do call :reportit endlocal goto :eof :reportit setlocal echo " Retrieving details for: %%D" echo " WHOIS: %%D" >> c:\whois-for-win32\results\domainlisting.txt echo "=============================================================" >> c:\whois-for-win32\results\domainlisting.txt whois %%D >> c:\whois-for-win32\results\domainlisting.txt timeout 8 endlocal

现在,假设所引用的数据文件每行只列出一个域。 显然,我这样做的原因是我们需要检查相当多的域名。

感谢您的想法和想法!

Hope someone can help. I've tried by googling this site but I'm either getting the wrong keywords or else I'm the first person to come across this issue (unlikely).

I'm trying to read a list of domains from a text file in a Windows batch file, which I'll post below. For each of those I'm trying to write the results to a file. I've looked at various uses of the "for /f" but can't fathom out what I need to do to get the line to work. Here's the code:

@setlocal @echo off for /F "tokens=1" %%D in (c:\whois-for-win32\domainlist.txt) do call :reportit endlocal goto :eof :reportit setlocal echo " Retrieving details for: %%D" echo " WHOIS: %%D" >> c:\whois-for-win32\results\domainlisting.txt echo "=============================================================" >> c:\whois-for-win32\results\domainlisting.txt whois %%D >> c:\whois-for-win32\results\domainlisting.txt timeout 8 endlocal

Now, assume the data file referred to has only one domain listed per line. Obviously the reason I'm doing this is that we've got a rather large number of domains to check.

Your thoughts and ideas all gratefully received!

最满意答案

如果使用FOR-Loops,则参数仅在for循环的上下文中可见。 在您的函数中,它不能作为%% D访问。

但你可以通过调用参数传递它们, 在这种情况下,我使用“%%〜D”,因为%% ~D删除封闭引号(如果有的话),然后我将其括在引号中以确保内容仅作为一个参数传递。

在函数中,传递的参数可以通过%1访问,但要删除引号,我使用%~1。

@echo off setlocal for /F "tokens=* EOL=# delims=" %%D in (c:\whois-for-win32\domainlist.txt) do call :reportit "%%~D" endlocal goto :eof :reportit setlocal set "domain=%~1" echo " Retrieving details for: %domain%" echo " WHOIS: %domain%" >> c:\whois-for-win32\results\domainlisting.txt echo "=============================================================" >> c:\whois-for-win32\results\domainlisting.txt whois %domain% >> c:\whois-for-win32\results\domainlisting.txt timeout 8 endlocal exit /b

If you use FOR-Loops the parameter is only visible in the context of the for-loop. In your function it's not accessible as %%D.

But you could pass them with the call as parameter, in this case I use "%%~D", as %%~D removes enclosing quotes if there are some and then i enclose it into quotes to ensure that the content will deliver as only one parameter.

In the function the passed parameter can be accessed via %1, but to remove the quotes I use %~1.

@echo off setlocal for /F "tokens=* EOL=# delims=" %%D in (c:\whois-for-win32\domainlist.txt) do call :reportit "%%~D" endlocal goto :eof :reportit setlocal set "domain=%~1" echo " Retrieving details for: %domain%" echo " WHOIS: %domain%" >> c:\whois-for-win32\results\domainlisting.txt echo "=============================================================" >> c:\whois-for-win32\results\domainlisting.txt whois %domain% >> c:\whois-for-win32\results\domainlisting.txt timeout 8 endlocal exit /b