在 Jenkins CI 上打开 Excel [英] Open Excel on Jenkins CI

查看:59
本文介绍了在 Jenkins CI 上打开 Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 7 上工作(作为会话 1 登录),我的 Jenkins CI 在会话 0 中作为 Windows 服务运行.我的问题是.. 我想在会话 0 中通过 Jenkins CI 打开一个 Excel 文件,但想在会话 1 上显示其 GUI.

I am working on Windows 7 (logged in as session no.1), my Jenkins CI is running as windows service in session 0. My problem is.. I want to open an Excel file through Jenkins CI in session 0, but want to display its GUI on session 1.

我知道会话 0 在 Windows 7 中是孤立的,但是是否可以在会话 0 中运行一个进程然后在另一个会话中输出?请帮忙.

I know that session 0 is isolated in Windows 7, but is it possible to run a process in session 0 and then output in another session? please help.

推荐答案


进行了一些试验和错误,但这最终对我有用(Windows 7 64 位).


Took a little trial and error, but this is what finally worked for me (Windows 7 64-bit).

  • 从 Microsoft 站点下载 PsTools
  • 我们只需要psexec.exe,但您可以提取所有内容.提取到 Jenkins 可访问的某个位置,最好路径中没有空格.
  • 打开提升的命令提示符:在开始的快速搜索中输入cmd,右键单击cmd.exe,选择以管理员身份运行.
  • 输入 C:path opsexec.exe -accepteula 并按 Enter.
  • 输入 C:path opsexec.exe -i 1 cmd 并回车.(如果您看到命令提示符出现,则一切正常,请立即关闭)
  • 在作业配置中,配置执行Windows批处理命令步骤
  • 写下以下内容:
    C:path opsexec.exe -accepteula &&C:path opsexec.exe -i 1 cmd/c start C:PROGRA~2MICROSO~1path oexcel.exe
  • Download PsTools from Microsoft site
  • We only need psexec.exe, but you can extract everything. Extract to some location accessible by Jenkins, preferably without spaces in the path.
  • Open elevated command prompt: type cmd into Start's quicksearch, right click cmd.exe, select Run as Administrator.
  • Type C:path opsexec.exe -accepteula and press enter.
  • Type C:path opsexec.exe -i 1 cmd and press enter. (If you see a command prompt appear, all is good, close it now)
  • In Job configuration, configure Execute Windows Batch command step
  • Write the following:
    C:path opsexec.exe -accepteula && C:path opsexec.exe -i 1 cmd /c start C:PROGRA~2MICROSO~1path oexcel.exe

地点:

  • C:path opsexec.exe 的完整路径,除非它在你的 %path%
  • -i 1 是您要在其中启动的会话 ID.
  • C:PROGRA~2MICROSO~1path oexcel.exe 没有空格的完整路径.由于大多数 Office 安装将位于带有空格的路径下,例如Program Files (x86)",因此您必须找出短路径,或者将其放置在没有空格的位置.
  • %path% 下拥有 excel.exe 并使用常规命令行还不够.
  • C:path o is your full path to psexec.exe, unless it is in your %path%
  • -i 1 is the session ID that you want to launch in.
  • C:PROGRA~2MICROSO~1path o is your full path to excel.exe without spaces. Since most Office installations are going to be under paths with spaces, like "Program Files (x86), you have to figure out the short path, or place it somewhere without spaces.
  • Having excel.exe under %path% and working from regular command line was not enough.

给关心的人一点解释:

  • psexec 需要先安装一个服务.为此,它需要第一次从提升的命令提示符运行.这是一次性安装步骤.
  • 要使 psexec 工作,您需要接受 EULA 提示.这是按会话/用户完成的.因此,即使您在命令提示符下运行 psexec -accepteula,当 Jenkins 服务(在会话 0 中作为本地系统运行)尝试使用它时,它也无济于事.因此,您必须将其与命令一起放入 Jenkins 作业中.从技术上讲,它只需要在那里一次,之后可以删除,但将它保留在那里绝对没有坏处.
  • 我使用了 cmd/k 并从本地 cmd 提示符运行此命令进行调试.这让我意识到我找不到逃避空格的方法(尝试了各种引用),所以不得不求助于短文件名.请注意,不需要短文件名,这只是为了转义空格.
  • psexec needs to install a services first. For that, it needs to be run from elevated command prompt for the first time. This is a one-time installation step.
  • To make psexec work, you need to accept the EULA prompt. This is done per session/user. So even if you run psexec -accepteula in your command prompt, it doesn't help when Jenkins service (running as Local System in session 0) tries to use it. Therefore, you have to place that into the Jenkins job, along with the command. Technically, it only needs to be there once, and can be removed afterwards, but it definitely doesn't hurt to keep it there.
  • I've used cmd /k and running this command from my local cmd prompt to debug. This is what made me realize I couldn't find a way to escape the spaces (tried various quoting), so had to resort to short file names. Note that short file names are not required, this is just to escape spaces.

这篇关于在 Jenkins CI 上打开 Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆