2016-01-26 75 views
0

我做了一個重啓2個服務的bat文件,我讓它在任務調度器中運行。如果我正常運行bat文件,我可以看到它作爲bat文件登錄到當前目錄。但如果我通過任務調度程序運行它,我可以看到蝙蝠運行,就像在服務窗口中,我可以看到服務重新啓動,但它不記錄任何東西....有誰知道問題是什麼?從任務調度程序運行時,Bat文件不記錄?

這是在windows server 2008 r2 64位。

感謝

@echo off 
SET waittimeseconds_sp_fix=15 
SET logfilename_sp_fix="SPSearchFix.log" 

echo %date% %time% - Restart starting >> %logfilename_sp_fix% 


net stop SPTimerV4 >> %logfilename_sp_fix% 2>&1 
if ERRORLEVEL 0 (
    echo %date% %time% - WORKED - Stopped timer service >> %logfilename_sp_fix% 
) ELSE (
    echo %date% %time% - FAILED - Stopped timer service >> %logfilename_sp_fix% 
    exit 
) 

timeout %waittimeseconds_sp_fix% 

net stop osearch14 >> %logfilename_sp_fix% 2>&1 
if ERRORLEVEL 0 (
    echo %date% %time% - WORKED - Stopped search service >> %logfilename_sp_fix% 
) ELSE (
    echo %date% %time% - FAILED - Stopped search service >> %logfilename_sp_fix% 
    exit 
)  

timeout %waittimeseconds_sp_fix% 

net start SPTimerV4 >> %logfilename_sp_fix% 2>&1 
if ERRORLEVEL 0 (
    echo %date% %time% - WORKED - Started timer service >> %logfilename_sp_fix% 
) ELSE (
    echo %date% %time% - FAILED - Started timer service >> %logfilename_sp_fix% 
    exit 
) 

timeout %waittimeseconds_sp_fix% 

net start osearch14 >> %logfilename_sp_fix% 2>&1 
if ERRORLEVEL 0 (
    echo %date% %time% - WORKED - Started search service >> %logfilename_sp_fix% 
) ELSE (
    echo %date% %time% - FAILED - Started search service >> %logfilename_sp_fix% 
    exit 
) 

timeout %waittimeseconds_sp_fix% 

echo %date% %time% - Restart completed >> %logfilename_sp_fix% 

echo. >> %logfilename_sp_fix% 
echo. >> %logfilename_sp_fix% 
echo. >> %logfilename_sp_fix% 
echo. >> %logfilename_sp_fix% 
echo. >> %logfilename_sp_fix% 
echo. >> %logfilename_sp_fix% 
+0

我想通了,它出於某種原因登錄到system32文件夾,但絕對路徑工作。 – omega

+0

嘗試爲日誌文件設置絕對路徑,如C:\ temp \ foo.log – Marged

回答

1

我建議確實正在創建的文件,但在「當前目錄」,其中批運行。

你可以後@echo off

設置當前目錄爲計劃任務

定義的一部分執行

cd "c:\your\desired\directory" 

爲第一線完整的拍檔名稱hanme。

BTW

if ERRORLEVEL 0 (

將爲所有意圖和目的始終是真實的,因爲它意味着「如果errorlevel大於0或0」。

你可以使用

if %errorlevel%==0 (

作爲替換。

相關問題