使用 PowerShell 脚本执行 EXE 文件 [英] Executing an EXE file using a PowerShell script

查看:297
本文介绍了使用 PowerShell 脚本执行 EXE 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 PowerShell 脚本执行 EXE 文件.如果我使用命令行,它可以正常工作(首先我提供可执行文件的名称和一系列参数来调用它):

I'm trying to execute an EXE file using a PowerShell script. If I use the command line it works without a problem (first I supply the name of the executable and series of parameters to invoke it):

"C:\Program Files\Automated QA\TestExecute 8\Bin\TestExecute.exe" C:\temp\TestProject1\TestProject1.pjs /run /exit /SilentMode

但是在脚本中执行完全相同的操作会返回错误:

But doing the exact same thing inside of a script returns an error:

术语 '"C:\Program Files\AutomatedQA\TestExecute 8\Bin\TestExecute.exe"C:\temp\TestProject1\TestProject1.pjs/run/exit/SilentMode' 不是被识别为 cmdlet 的名称,函数、脚本文件或可操作的程序.检查拼写名称,或者如果包含路径,验证路径是否正确并且再试一次.

The term '"C:\Program Files\Automated QA\TestExecute 8\Bin\TestExecute.exe" C:\temp\TestProject1\TestProject1.pjs /run /exit /SilentMode' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

(我使用&"运算符调用了该命令.)

(I invoked the command using the "&" operator.)

我该如何解决这个问题?

How can I fix this problem?

推荐答案

& "C:\Program Files\Automated QA\TestExecute 8\Bin\TestExecute.exe" C:\temp\TestProject1\TestProject1.pjs /run /exit /SilentMode

[System.Diagnostics.Process]::Start("C:\Program Files\Automated QA\TestExecute 8\Bin\TestExecute.exe", "C:\temp\TestProject1\TestProject1.pjs /run /exit /SilentMode")

更新:抱歉,我错过了(我使用&"运算符调用命令)"句子.我在动态评估路径时遇到了这个问题.尝试调用表达式构造:

UPDATE: sorry I missed "(I invoked the command using the "&" operator)" sentence. I had this problem when I was evaluating the path dynamically. Try Invoke-Expression construction:

Invoke-Expression "& `"C:\Program Files\Automated QA\TestExecute 8\Bin\TestExecute.exe`" C:\temp\TestProject1\TestProject1.pjs /run /exit /SilentMode"

这篇关于使用 PowerShell 脚本执行 EXE 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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