Powershell.exe 在 cli 或包装器中运行脚本?
我有一个第三方应用程序,可以通过添加执行数据转换等的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Powershell 希望在运行脚本文件之前有一个合格的路径。 因此,如果它位于当前工作目录中,您需要使用
(对于此用例来说不太可能且容易中断),或者使用脚本的完整路径:
或类似的。
Powershell wants to have a qualified path to script files before it will run them. So you need to either use
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:
or similar.
您还可以尝试
Powershell.exe -Command "& your-app.exe ${your-arguments}
You can also try
Powershell.exe -Command "& your-app.exe ${your-arguments}