2011-02-23 133 views
1

我目前正在研究一個文件或文件可以轉儲到服務器上多個位置之一的項目。我有一個在MATLAB中設置的例程,它能很好地處理這些文件,並且我想將它自動化,這樣我就不必再浪費時間來處理這些文件。將文件添加到文件夾時運行MATLAB例程

我發現了一個WMI腳本(來自ScriptingGuy Here),它的行爲方式適用於我,除非我不瞭解WMI將其更改爲我的用途。

strComputer = "." 
Set objWMIService = GetObject("winmgmts:" _ 
    & "{impersonationLevel=impersonate}!\\" & _ 
    strComputer & "\root\cimv2") 
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _ 
    ("SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE " _ 
    & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _ 
    & "TargetInstance.GroupComponent= " _ 
    & "'Win32_Directory.Name=""c:\\\\scripts""'") 
Do 
    Set objLatestEvent = colMonitoredEvents.NextEvent 
    Wscript.Echo objLatestEvent.TargetInstance.PartComponent 
Loop 

我嘗試使用命令行工具MATLAB替換Wscript.Echo行

matlab -automation -r someRoutine(varargin) 

這慘遭失敗。

有人請給我一些關於從WMI正確調用MATLAB並將目標目錄更改爲服務器上的多個目錄的指導?

回答

1

您正在尋找WScript.ShellRun方法:

Set objShell = WScript.CreateObject("WScript.Shell")  
objShell.Run "matlab -automation -r someRoutine(varargin)" 

documentation介紹可選參數,使您可以控制如何顯示在創建的過程中,你是否不等待它完成。

相關問題