Use vbs to batch run commands

     
  
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  
' The function used to check whether the given file exists.                     '  
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  
Function CheckFileExists(strFilePath)   
    set oFSO = createObject("Scripting.FileSystemObject")   
    boolFileExists = oFSO.fileExists(strFilePath)    
    set oFSO = Nothing    
      
    CheckFileExists = boolFileExists   
End Function  

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  
' The function used to print log                                                '  
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  
Function PrintLog(strLog, logFileName)  
	if not CheckFileExists(logFileName) then
		Set fso = CreateObject("Scripting.FileSystemObject") 
		fso.CreateTextFile logFileName, true
		Set fso = nothing
	end if
	
	Set fso = CreateObject("Scripting.FileSystemObject") 
	Const ForAppending = 8
	Set objLogFile = fso.OpenTextFile(logFileName, ForAppending, True)	
	
	strMsg = Date() & " " & Time() & " " & strLog  
    objLogFile.WriteLine strMsg  
	
	objLogFile.Close()
	Set fso = nothing
End Function 

  
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  
' The RunCommandlineTool function execute the specified command-line exe,       '  
' and redirect the command-line print messages to the given log file,           '  
' then analyze the log file to determine whether there are some errors.         '  
'                                                                               '  
' PARAMETERS:                                                                   '  
'   @strCommand: Specify the command string,                                    '  
'   @strRedirectLogFilenamePath: Specify the log file,                          '  
' RETURN:                                                                       '  
'   True : process succeed without any error,                                   '  
'   False: process complete with some errors                                    '                                             
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  
Function RunCommandlineTool(strCommand, logFileName)  
    PrintLog """" & strCommand & """" & " Start!", logFileName     
      
    Set WsShell = CreateObject("Wscript.Shell")   
    Dim strShellCommand   
    Dim processNoError  
      
    strShellCommand = "%comspec% /c " & Chr(34) & strCommand & " >> " & logFileName & Chr(34)  
    WsShell.Run strShellCommand, 0, True                                          
    
End Function   


Dim scriptFileName
Dim logFileName
scriptFileName = WScript.Arguments(0)  
logFileName = WScript.Arguments(1)  
  
Set fso1 = createobject("scripting.filesystemobject")  
Set textStream = fso1.OpenTextFile(scriptFileName, 1)  
  
Do While Not textStream.AtEndOfStream  
	cmdLine = trim(textStream.readline)		
	i=i + 1   	
	  
	RunCommandlineTool cmdLine, logFileName   
Loop   
  
Set textStream = Nothing  
Set fso1 = Nothing   
      
    

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值