繁体   English   中英

如何通过在 powershell 中提供配置文件来运行可执行文件 (exe)

[英]How to run an executable (exe) by providing a config file in powershell

我正在尝试通过提供配置文件(在我的情况下为 yml)在后台运行 exe

尝试了以下方法,但这并没有将执行推到后台。 -

./my.exe start --config-file $my_config_file

找到专门用于这种情况的“启动进程”命令。 使用参数列表有没有办法发送配置文件?

Start-Process -Wait -FilePath "my.exe" -ArgumentList 

删除-Wait参数并通过-ArgumentList参数将进程 arguments 作为数组传递:

Start-Process -FilePath "my.exe" -ArgumentList 'start', '--config-file', "`"$my_config_file`""

需要对$my_config_file进行奇怪的引用,因为路径可能包含空格。 Start-Process不进行自动报价。 文档

如果参数或参数值包含空格,则需要用转义的双引号将它们括起来。

请注意,如果这对您很重要,您将不会收到启动过程的 output。 您可以使用参数-RedirectStandardOutput-RedirectStandardError重定向到文件,但不能(轻松)将 output 存储在变量中。

在后台启动进程,同时能够接收其 output 的一种方法是创建一个作业

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM