Powershell.exe 在 cli 或包装器中运行脚本?

发布于 2024-07-22 21:18:10 字数 500 浏览 7 评论 0原文

我有一个第三方应用程序,可以通过添加执行数据转换等的 exe 文件来扩展。我在 Powershell 中编写了一个扩展来执行我想要的转换,但我无法让第三方应用程序运行我的 ps1 ,因为它只接受 .exe 文件作为扩展名。 该应用程序将文件名添加为扩展的第一个(也是唯一的)命令行参数,因此它运行的命令如下所示:

someprogram.exe somefile.xml

我试图让它以我的脚本作为参数运行 Powershell.exe,但我无法弄清楚如何以及是否可能。 我尝试过的一些东西

powershell.exe myscript.ps1

行不通。 我尝试让脚本找到正确的 XML 文件本身,但不知怎的,我仍然无法让 Powershell 运行命令行并以脚本作为参数并运行它。

接下来我考虑编写一个仅运行 Powershell 脚本的小 .exe 文件,但这可能吗? 如果是,有人可以将我推向正确的方向吗?

I have a third-party application that's extensible by adding exe-files that perform dataconversion etc. I've written an extension in Powershell that does the conversion I want, but I'm unable to get the third-party app to run my ps1, as it will only accept an .exe file as an extension.
The app adds a filename as the first (and only) commandline argument to the extension, so the command it runs looks like:

someprogram.exe somefile.xml

I tried to get it to run Powershell.exe with my script as an argument, but I haven't been able to figure out how and if that's possible. Some stuff I tried like

powershell.exe myscript.ps1

won't work. I tried getting the script to find the correct XML file itself, but still somehow I couldn't get Powershell to run off the commandline and take a script as an argument and run it.

Next I thought about writing a small .exe file that only runs the Powershell script, but is that even possible? If it is, could someone nudge me in the right direction?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

淡看悲欢离合 2024-07-29 21:18:10

Powershell 希望在运行脚本文件之前有一个合格的路径。 因此,如果它位于当前工作目录中,您需要使用

powershell.exe .\myscript.ps1

(对于此用例来说不太可能且容易中断),或者使用脚本的完整路径:

powershell.exe C:\Users\Foo\Scripts\myscript.ps1

或类似的。

Powershell wants to have a qualified path to script files before it will run them. So you need to either use

powershell.exe .\myscript.ps1

if it lies in the current working directory (unlikely and prone to break for this use case) or use the full path to the script:

powershell.exe C:\Users\Foo\Scripts\myscript.ps1

or similar.

月竹挽风 2024-07-29 21:18:10

您还可以尝试 Powershell.exe -Command "& your-app.exe ${your-arguments}

You can also try Powershell.exe -Command "& your-app.exe ${your-arguments}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文