2014-07-23 108 views
0

我有一個批處理文件(batch1.bat),用於檢查UNC共享上的更新版本,然後運行一些命令。但是,問題是我想更新共享上的批處理文件,以便將來的更新在運行批處理時應用於所有用戶。問題是批處理文件在檢查時不會更新爲正在運行。如何在使用批處理文件時從UNC路徑更新批處理文件

實施例:

mkdir C:\program\Tools 
xcopy /D /Y /e "\\UNC_Share\program\*.*" "C:\program\" 

這將複製批處理文件工具文件夾。

我創建了一個名爲update.bat的新文件,它調用上面的xcopy命令,然後打開原始批處理文件(batch1.bat)來完成它的工作。但是,無法弄清楚如何讓batch1.bat調用更新,關閉並重新打開批處理,而無需在循環中調用更新。

  1. 用戶打開(運行)batch1.bat。
  2. Batch1.bat調用update.bat並關閉batch1.bat,以便它可以從UNC共享中更新。
  3. 更新完成後,update.bat會調用batch1.bat,並運行這些工具。

文件在UNC共享

\\UNC_Share\program\ 
    batch1.bat 
    update.bat 
\\UNC_Share\program\Tools 
    some .exe and .dll files 

回答

0

這是沒有問題的運行從一個批處理文件中的批處理文件,而不使用在停止處理當前的批處理文件命令call結果,並繼續處理上開始批文件。

batch1.bat:

​​

update.bat:

@echo off 
echo Updating tools, please wait ... 

rem Target directory automatically created because of switch /I if not exist. 
xcopy /D /Y /E /I /Q "\\UNC_Share\program\*" "C:\program\Tools\" 1>nul 

rem If there was no argument passed on running this batch file, there 
rem is nothing else to do. Otherwise it is expected that the first 
rem argument is the name of the batch file which started this batch 
rem file for updating the tools and therefore start this batch file 
rem now again after setting the environment variable "UpdateDone". 
if not "%~1"=="" (
    set UpdateDone=yes 
    %1 
)