简单的bat文件logging到文本,但错误

我创build了2个简单的蝙蝠文件,而且我一直在得到同样的错误。 我想将蝙蝠文件上的内容logging到文本文件中。 错误是: 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 

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

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

 type filename > logfile 

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

我相信是这样。 我已经添加了另一个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文件和命令行),这是非常有用的。