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:
我有一个第三方应用程序可以通过添加执行dataconversion等的exe文件进行扩展。我已经在Powershell中编写了一个扩展,它可以进行我想要的转换,但是我无法让第三方应用程序运行我的ps1 ,因为它只接受.exe文件作为扩展名。该应用程序添加一个文件名作为扩展的第一个(也是唯一的)命令行参数,因此它运行的命令如下所示:
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,但我无法弄清楚如何以及是否可能。我试过的一些东西
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.
不行。我尝试让脚本找到正确的XML文件本身,但仍然不知何故我无法让Powershell运行命令行并将脚本作为参数并运行它。
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?
接下来我考虑编写一个只运行Powershell脚本的小.exe文件,但这是否可能呢?如果是的话,有人可能会朝着正确的方向推动我吗?
2 个解决方案
#1
Powershell wants to have a qualified path to script files before it will run them. So you need to either use
Powershell希望在运行脚本之前拥有一个合格的脚本文件路径。所以你需要使用
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.
#2
You can also try Powershell.exe -Command "& your-app.exe ${your-arguments}
您还可以尝试Powershell.exe -Command“&your-app.exe $ {your-arguments}
#1
Powershell wants to have a qualified path to script files before it will run them. So you need to either use
Powershell希望在运行脚本之前拥有一个合格的脚本文件路径。所以你需要使用
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.
#2
You can also try Powershell.exe -Command "& your-app.exe ${your-arguments}
您还可以尝试Powershell.exe -Command“&your-app.exe $ {your-arguments}