2013-05-29 113 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

我敢打賭,您嘗試刪除/寫入的文件是由另一個程序打開的。也許記事本?

相關問題