首页 > 解决方案 > Rundeck 如何在我的机器上启动 Excel 文件?

问题描述

我有一个用户界面,它在名为 BatForRundeck 的目录上生成一组 CSV 文件(每个用户几个)、xlsm 文件(每个用户一个)和 .bat 文件(每个用户一个)。这些 CSV 文件的处理由生成的 xlsm 文件完成。此 xlsm 由带有参数但对所有用户通用的 VBScript 文件启动。VBScript 文件由生成的 .bat 启动。该处理链应使用 Rundeck 自动化。我正在使用循环 BatForRundeck 目录来处理用户生成的 .bat 的新 .bat。代码如下:

@echo off 
for %%f in (C:\Users\myUserName\Documents\BatForRundeck\*10000*.bat) do call %%f

这个 .bat 程序在我的电脑上运行良好。但在 Rundeck 上,该程序运行但它不启动 Excel (xlsm) 并且不处理 CSV 文件。

然后我尝试了另一种变体:

@echo off 
for %%f in (C:\Users\myUserName\Documents\BatForRundeck\*10000*.bat) do echo call %%f >> C:\Users\myUserName\Documents\BatForRundeck\toto.bat
start C:\Users\myUserName\Documents\BatForRundeck\toto.bat

备注:我没有删除 toto.bat,因为我想看看它包含什么。

我有同样的结果,这个 .bat 在我的电脑上运行良好。但在 Rundeck 上,该程序不会启动 Excel (xlsm)。

toto.bat 的示例内容:

call C:\Users\myUserName\Documents\BatForRundeck\Macro_RSI_V10_4-10000442896544.bat 
call C:\Users\myUserName\Documents\BatForRundeck\Macro_RSI_V10_4-10000880367985.bat 

.bat Macro_RSI_V10_4-10000442896544.bat 具有以下代码:

@echo off 
C:\Users\myUserName\Documents\BatForRundeck\Macro_RSI_V10_4.OID.vbs  Macro_RSI_V10_4.10000442896544.xlsm

Macro_RSI_V10_4-10000880367985.bat 包含:

@echo off 
C:\Users\myUserName\Documents\BatForRundeck\Macro_RSI_V10_4.OID.vbs  Macro_RSI_V10_4.10000880367985.xlsm

VBS Macro_RSI_V10_4.OID.vbs 程序包含以下代码:

'Microsoft Excel Automation Basics
':: Open and Execute an Excel File.
'---------------------------------
'Retrieve the parameters that were passed.
Dim Arg
Set Arg = WScript.Arguments

'The first parameter begins with 0 as index.
Dim MacroName
MacroName = Arg(0) 'Ex : Macro_RSI_V10_4.10000442896544.xlsm

'create the excel object
Set objExcel = CreateObject("Excel.Application") 

'view the excel program and file, set to false to hide the whole process
objExcel.Visible = False 

'open an excel file (make sure to verify the location) .xls for 2003 or earlier
Set objWorkbook = objExcel.Workbooks.Open("C:\Users\myUserName\Documents\BatForRundeck\" & MacroName)  
'close the workbook
'objWorkbook.Close 

'exit the excel program
objExcel.Quit

'release objects
Set objExcel = Nothing
Set objWorkbook = Nothing

Rundeck 和我的电脑之间的通信工作正常。我设法启动 .bat 以 .txt 或 .csv 格式创建文本文件。但我无法启动 Excel。我要问的问题是,是否有某种方法可以让 Rundeck 特殊程序在我的机器或另一台远程机器上运行 Excel 文件?

标签: excelbatch-filerundeck

解决方案


一个简单的解决方案是使用 python 脚本来启动您的文件,您可以在指向您的 Windows 机器的 Rundeck 作业上创建一个内联 python 脚本(或调用外部脚本) 。当然,你需要在你的 Windows 机器上安装python 解释器。


推荐阅读