批量错误 - “此进程无法访问,因为该文件正在被另一个进程使用”

问题描述 投票:0回答: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
batch-file
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.