简单的bat文件记录到文本但是错误

时间:2012-10-16 18:18:39

标签: windows command-line batch-file

我创建了两个简单的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

2 个答案:

答案 0 :(得分:1)

此问题不是因为您从内部调用bat文件。在dos中执行此操作是完全可以接受的。

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

type filename > logfile

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

答案 1 :(得分: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&gt;&amp; 1正在记录每个文本(来自bat文件和命令行),这非常有用。