帮自己一个忙,学习 Powershell 或 python。我曾经构建疯狂的批处理文件来自动化流程,它们很痛苦。
Powershell 在构建此类条件脚本方面要好得多,尤其是具有创建和监视子线程的能力。Python 在这方面也很棒。
这些带来的最大优势是您可以访问数据库(以及脚本中的返回结果以处理和响应数据。
缺点(?)是你需要学习其中一种语言,但我个人并不认为这些是缺点,因为它们比批处理文件要好得多。
否则, foxidrive 的答案应该适合你。
Powershell 示例(有点长,但代码可以重用):
function CreateConnection
{
param([string]$databaseHost
,[string]$Port
,[string]$SID
,[string]$UserID
,[string]$Password
)
process
{
$ConnectString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST={0})(PORT={1}))(CONNECT_DATA=(SID={2})));User Id={3};Password={4};"`
-f $databaseHost,$port,$SID,$UserID,$Password
write-host $connectString
sleep 10
$connection = new-object system.data.oracleclient.oracleconnection( $ConnectString)
return $connection
}
}
$DBMSHost="somehost.somedomain.com"
$DBMSPort=1521
$SID="somesid"
$UserName="user"
$Password="password"
[System.Reflection.Assembly]::LoadWithPartialName('System.Data.OracleClient') | out-null
try {
$Connection = CreateConnection $DBMSHost $DBMSPort $SID $UserName $Password
}
catch
{
write-host ("Could not access Oracle database {0}" -f $_.Exception.ToString())
exit
}
$Query = "SELECT COUNT(*) as rowcount FROM dmsn.ds3r_1xrtt_voice_trigger" // Added name to column to make life easier
$data_set = new-object system.data.dataset
$adapter = new-object system.data.oracleclient.oracledataadapter ($Query, $Connection)
[void] $adapter.Fill($data_set)
$table = new-object system.data.datatable
$table = $data_set.Tables[0] // We now have the actual resukts data
foreach ($row in $table)
{
if ($row.rowcount <1 )
{
$Application = "C:\Autobatch\Spotfire.Dxp.Automation.ClientJobSender.exe"
$Arguments = "http://SERVER/spotfireautomation/JobExecutor.asmx c:\AutoBatch\backup\Trigger_Test.xml"
$CommandLine = "{0} {1}" -f $Application,$Arguments
invoke-expression $CommandLine
}
}