gpt4 book ai didi

windows - 使用参数启动进程 powershell.exe

转载 作者:可可西里 更新时间:2023-11-01 11:24:45 26 4
gpt4 key购买 nike

如何启动一个新的 powershell 实例并告诉该实例执行特定命令?

我尝试过的:

(假设 vim.exefile.txt 在 cwd 中)

启动-Process powershell.exe .\vim.exe .\file.txt

vim.exepowershell.exe

的参数

file.txtvim.exe

的参数

错误说:

Start-Process : A positional parameter cannot be found that accepts argument 
'.\file.txt'.At line:1 char:1
+ Start-Process powershell.exe .\vim.exe .\file.txt
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Start-Process], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.StartProcessCommand

我也试过 powershell.exe -ArgumentList {.\vim.exe .\file.txt} 但没有骰子。

最佳答案

参数列表是一个数组...比如说 start-process 不知道如何处理 .\file.txt

我是这样写的

 Start-Process powershell.exe -ArgumentList @('.\vim.exe', '.\file.txt')

下面的也可以,但我喜欢上面你明确说你想要一个数组的地方

 Start-Process powershell.exe -ArgumentList '.\vim.exe', '.\file.txt'

关于windows - 使用参数启动进程 powershell.exe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41884011/

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