1

我创建了 2 个简单的 bat 文件,但我不断收到相同的错误。我想将 bat 文件中的内容记录到文本文档中。错误是:The process cannot access the file because it is being used by another process. 是因为我被称为本身的bat文件吗?

代码 1

@echo off

:BEGIN
net stop redmineMongrel1
TIMEOUT /T 15
net start redmineMongrel1
goto SUCCESS

:SUCCESS
"C:\Documents and Settings\Administrator\My Documents\MongrelRestartScript.bat" > "C:\Documents and Settings\Administrator\My Documents\MongrelRestart.log"
ECHO Mongrel Restart Successful  %DATE%>> "C:\Documents and Settings\Administrator\My Documents\MongrelRestart.log"
goto END

:FAIL
ECHO.>"C:\Documents and Settings\Administrator\My Documents\MongrelRestart.log"
ECHO Mongrel Restart FAILED %DATE%>> "C:\Documents and Settings\Administrator\My Documents\MongrelRestart.log"

:END
echo END OF BAT FILE

代码 2

@echo off


:BEGIN
DEL "D:\BACKUPS\RedmineFolder" /s /q 
RD "D:\BACKUPS\RedmineFolder" /s /q


xcopy C:\BitNami\apps\redmine "D:\BACKUPS\RedmineFolder" /e /h /r /y /I
goto SUCCESS

:SUCCESS
ECHO.>"C:\Documents and Settings\Administrator\My Documents\RedmineBackupLog.log"
ECHO Redmine Backup Successful  %DATE%>> "C:\Documents and Settings\Administrator\My Documents\RedmineBackupLog.log"
"C:\Documents and Settings\Administrator\My Documents\RedmineBackUpScript.bat" >> "C:\Documents and Settings\Administrator\My Documents\RedmineBackupLog.log"
goto END

:FAIL
ECHO.>"C:\Documents and Settings\Administrator\My Documents\RedmineBackupLog.log"
ECHO Redmine Backup  FAILED %DATE%>> "C:\Documents and Settings\Administrator\My Documents\RedmineBackupLog.log"

:END
echo END OF BAT FILE
4

2 回答 2

1

这个问题不是因为你从内部调用 bat 文件。在 dos 中这样做是完全可以接受的。

如果您尝试转储 bat 文件的内容,请使用 'type' :

type filename > logfile

您的 .log 文件很可能已被另一个进程打开。您可以使用 windows 的 filemon 来查看哪些进程可能正在访问该文件:filemon

于 2012-10-16T18:27:08.050 回答
1

我相信是这样的。我添加了另一个 bat 文件来调用这个文件,如下所示:

MAIN.bat

"C:\Documents and Settings\Administrator\My Documents\DoThis.bat" > "C:\Documents and Settings\Administrator\My Documents\LogEverything.log" 2>&1

2>&1 正在记录每个文本(来自 bat 文件和命令行),这非常有用。

于 2012-10-17T15:19:17.813 回答