gpt4 book ai didi

powershell - 使用 PowerShell 脚本执行 EXE 文件

转载 作者:行者123 更新时间:2023-12-03 04:49:08 51 4
gpt4 key购买 nike

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

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

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

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.

(我使用“&”运算符调用该命令。)

如何解决这个问题?

最佳答案

& "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")

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

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

关于powershell - 使用 PowerShell 脚本执行 EXE 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4639894/

51 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com