简体   繁体   English

Start-Process参数在Function中不起作用

[英]Start-Process arguments not working within Function

Ok, so I was looking for a quick way to run the current script in ISE that I'm working on in an external PS window - it's going to be used by the team so I wanted to work out formatting and that the menu options displayed correctly etc 好的,所以我正在寻找一种快速方法来在外部PS窗口中运行的ISE中运行当前脚本-团队将使用该脚本,因此我想确定格式并显示菜单选项正确地等

This finds the current tab file script in ISE: 这将在ISE中找到当前的选项卡文件脚本:

$ArgList = $psISE.CurrentFile.FullPath

This launches a new Powershell window and runs the script (file argument constructed in case script has a space in the path): 这将启动一个新的Powershell窗口并运行脚本(如果脚本在路径中有空格,则构造文件参数):

start-process -FilePath powershell.exe -ArgumentList "-file `"$($ArgList.path)`""

Running these two consecutively and interactively works fine 连续运行这两个并进行交互可以正常运行

Problem being, if I run the two within a function like this: 问题是,如果我在这样的函数中运行两者:

Function ISERunInNewWindow {
$ArgList = $psISE.CurrentFile.FullPath
start-process -FilePath powershell.exe -ArgumentList "-file `"$($ArgList.path)`""
}

...it produces this error: ...它产生此错误:

Processing -File ' ' failed: The path is not of a legal form. 处理-File''失败:路径不是合法形式。 Specify a valid path for the -File parameter. 为-File参数指定有效路径。

I know I must be missing something obvious, but it's eluding me as I don't use Powershell too often - any ideas? 我知道我肯定会遗漏一些显而易见的东西,但是由于我不经常使用Powershell,这使我难以理解-有什么想法吗?

Ok - for anyone's info - it WAS something obvious as suspected. 好的-对于任何人的信息-这都是显而易见的怀疑。

Amending this: 修改此:

start-process -FilePath powershell.exe -ArgumentList "-file `"$($ArgList.path)`""

To this: 对此:

start-process -FilePath powershell.exe -ArgumentList "-file `"$($ArgList)`""

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

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