2013-05-29 105 views
1

我试图运行一个文件以便在ping主机文件名列表后获取IP。批处理错误 - “此进程无法访问,因为该文件正在被另一个进程使用”

当我尝试运行它,我得到的错误

我能做些什么来解决它“因为该文件正被另一个进程使用这个过程不能访问”?

@ECHO OFF 
COLOR 1f 

:HEADER 
CLS 
ECHO ------------------------------------------------------------------------------- 
ECHO AUTHOR:   Levon Becker 
ECHO TITLE:   Ping-List 
ECHO LAST CHANGE: 04/08/2010 
ECHO VERSION:  1.002 
ECHO LINK:   http://wiki.bonusbits.com/main/BatchScripts:Ping_List 
ECHO ------------------------------------------------------------------------------- 
ECHO. 
PAUSE 

:NOTES 
REM  +The text file with your list of hostnames should be named hostlist.txt 
REM  +The hostnames can be seperated by a comma or carriage return 
REM  +The output file will be a text file named PingResults.txt 
REM  +The output file is setup to be comma delimited for easy import to Excel 
REM  +Changed output file to be csv 

REM Delete the output file if it exists from a previous run. 
IF EXIST "PingResults.txt" del /q PingResults.txt 

REM Delete the temp file. 
IF EXIST "pinglog" del /q pinglog 

REM Description Header for top row in Excel 
ECHO Hostname,IP from Ping,Ping Status,Data of Ping,Time of Ping > PingResults.csv 

REM Pull hostnames from text file until the end of the text file list 
for /f "tokens=* delims=," %%I in (hostlist.txt) do call :sub1 %%I 
goto :eof 

:sub1 

REM Display in the command window which hostname is being processed so we know 
REM something is happening. 
ECHO %1 

REM Ping the current hostname set as %1 and redirect the output to pinglog file. 
ping -a -n 1 -w 500 %1 > pinglog 

PAUSE 

SET status=UNKNOWN 

find /i "unknown host" <pinglog> nul 
if not errorlevel 1 set status=UNKNOWN HOST 

find /i "could not find host" <pinglog> nul 
if not errorlevel 1 set status=HOST NOT FOUND 

find /i "reply" <pinglog> nul 
if not errorlevel 1 set status=UP 

find /i "expired in transit" <pinglog> nul 
if not errorlevel 1 set status=EXPIRED IN TRANSIT 

find /i "Request timed out" <pinglog> nul 
if not errorlevel 1 set status=DOWN 

PAUSE 

SET PINGIP=NO IP 

REM Pull the IP address of the line that has Pinging in it and IP between [] 
FOR /F "tokens=1,2 delims=[]" %%A IN ('FIND "Pinging" pinglog') DO IF NOT "%%B"=="" SET PINGIP=%%B 

REM Append line of gathered information including the hostname from the source. 
REM No spaces so it falls into Excel easier 
>> PingResults.csv echo %*,%PINGIP%,%status%,%DATE%,%TIME% 

REM Delete the temp file. 
IF EXIST "pinglog" del /q pinglog 
PAUSE 

goto :eof 

COLOR 1a 
CLS 
ECHO. 
ECHO ********************************************* 
ECHO ********************************************* 
ECHO **           ** 
ECHO **   PROCESS COMPLETED!   ** 
ECHO **           ** 
ECHO ** The Output Filename is PingResults.txt ** 
ECHO **           ** 
ECHO ********************************************* 
ECHO ********************************************* 
ECHO. 
ECHO. 
PAUSE 

:END 
exit 
+0

我会尝试“回声和”>“之间的长线,我认为逗号','可能是一个问题 – flaschenpost

+1

请你能缩小错误的范围,我不能读这段代码。 – Endoro

回答

0

我敢打赌,您尝试删除/写入的文件是由另一个程序打开的。也许记事本?

相关问题