Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在powershell中运行“启动powershell”时设置窗口标题不工作?_Powershell - Fatal编程技术网

在powershell中运行“启动powershell”时设置窗口标题不工作?

在powershell中运行“启动powershell”时设置窗口标题不工作?,powershell,Powershell,以下命令在CMD中工作 但它在Powershell中不起作用 PS C:\> start powershell -noexit -command "$Host.UI.RawUI.WindowTitle = 'test'; read-host" Start-Process : A parameter cannot be found that matches parameter name 'noexit'. At line:1 char:18 + start powershell -noexit -

以下命令在CMD中工作

但它在Powershell中不起作用

PS C:\> start powershell -noexit -command "$Host.UI.RawUI.WindowTitle = 'test'; read-host" Start-Process : A parameter cannot be found that matches parameter name 'noexit'. At line:1 char:18 + start powershell -noexit -command "$Host.UI.RawUI.WindowTitle = 'test ... + ~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Start-Process], ParameterBindingException + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.StartProcessCommand 但是,新窗口显示以下错误消息,并且未设置标题

System.Management.Automation.Internal.Host.InternalHost.UI.RawUI.WindowTitle : The term 'System.Management.Automation.Internal.Host.InternalHost.UI.RawUI.WindowTitle' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + System.Management.Automation.Internal.Host.InternalHost.UI.RawUI.Wind ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (System.Manageme...wUI.WindowTitle:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException 在命令提示下,启动为。在Windows Powershell中,start是的别名,它执行类似的操作,但不完全相同

尝试运行以下命令:

powershell -NoExit -command "`$Host.UI.RawUI.WindowTitle = 'bits'"
在命令提示下,启动为。在Windows Powershell中,start是的别名,它执行类似的操作,但不完全相同

尝试运行以下命令:

powershell -NoExit -command "`$Host.UI.RawUI.WindowTitle = 'bits'"
解释cmd.exe中的start与PowerShell中的start不同

按如下方式使用,以获得所需的结果;请注意,powershell隐式绑定到参数-FilePath,而以-NoExit开头的、-分隔参数隐式绑定到-ArgumentList-Args参数,该参数接受字符串数组:

在特殊情况下,必须引用带前缀的传递参数,这样它们就不会被误认为是启动进程自己的参数

还请注意$in$Host前面的`防止调用PowerShell实例预先插入$Host

您还可以使用“$Host.UI.RawUI.WindowTitle=bits”,这是一个单引号文字字符串,其中嵌入单引号,并转义为

重要:

虽然从概念上讲,将参数作为数组传递给ArgumentList是最好的方法,但不幸的是,由于启动过程中存在一个长期存在的bug,这是不明智的,在编写v7.1时仍然存在,请参阅

现在,使用一个包含所有参数的字符串,包含在嵌入的。。。必要时引用是唯一通常稳健的方法。正如链接的GitHub问题中所讨论的,将来可能会引入一个-ArgumentArray参数,该参数支持健壮的基于数组的参数传递

在本案中,这意味着以下内容,如在对问题的评论中所建议的:

Start-Process powershell '-NoExit -command "$Host.UI.RawUI.WindowTitle = ''bits''"'
请注意整个参数列表字符串的单引号“…”,这需要将嵌入的单引号转义为“”,PowerShell应该将这些单引号视为命令的一部分。 解释cmd.exe中的start与PowerShell中的start不同

按如下方式使用,以获得所需的结果;请注意,powershell隐式绑定到参数-FilePath,而以-NoExit开头的、-分隔参数隐式绑定到-ArgumentList-Args参数,该参数接受字符串数组:

在特殊情况下,必须引用带前缀的传递参数,这样它们就不会被误认为是启动进程自己的参数

还请注意$in$Host前面的`防止调用PowerShell实例预先插入$Host

您还可以使用“$Host.UI.RawUI.WindowTitle=bits”,这是一个单引号文字字符串,其中嵌入单引号,并转义为

重要:

虽然从概念上讲,将参数作为数组传递给ArgumentList是最好的方法,但不幸的是,由于启动过程中存在一个长期存在的bug,这是不明智的,在编写v7.1时仍然存在,请参阅

现在,使用一个包含所有参数的字符串,包含在嵌入的。。。必要时引用是唯一通常稳健的方法。正如链接的GitHub问题中所讨论的,将来可能会引入一个-ArgumentArray参数,该参数支持健壮的基于数组的参数传递

在本案中,这意味着以下内容,如在对问题的评论中所建议的:

Start-Process powershell '-NoExit -command "$Host.UI.RawUI.WindowTitle = ''bits''"'
请注意整个参数列表字符串的单引号“…”,这需要将嵌入的单引号转义为“”,PowerShell应该将这些单引号视为命令的一部分。
这是另一种方法,同时避免美元符号。双引号必须在外部,以便位保持被引用

start powershell "-noexit (get-variable host).value.ui.rawui.windowtitle = 'bits'"
将命令放入文件中,始终可以避免这些引用问题

start powershell '-noexit .\window.ps1'

这是另一种方法,同时避免美元符号。双引号必须在外部,以便位保持被引用

start powershell "-noexit (get-variable host).value.ui.rawui.windowtitle = 'bits'"
将命令放入文件中,始终可以避免这些引用问题

start powershell '-noexit .\window.ps1'

使用用于设置窗口标题的命令选项启动powershell对我不起作用。可能是因为我想用ps1文件打开另一个powershell。在另一个ps1文件中,我添加了第一行,如下所示

获取Host.ui.RawUI.WindowTitle='TEST'


它就像一个魔咒……

使用命令选项启动powershell以设置窗口标题对我来说不起作用。可能是因为我想用ps1文件打开另一个powershell。在另一个ps1文件中,我添加了第一行,如下所示

获取Host.ui.RawUI.WindowTitle='TEST'


它就像一个符咒一样,不会弹出一个新窗口。我想弹出一个新窗口。我实际上需要并行运行多个窗口。它不会弹出新窗口。我想弹出一个新窗口。我实际上需要并行运行多个窗口
el.start powershell'-NoExit-command$Host.UI.RawUI.WindowTitle=bits'start powershell'-NoExit-command$Host.UI.RawUI.WindowTitle=bits'或更短的命令:Get-Host。如您的示例所示,默认动词逻辑很吸引人,但模糊且脆弱。此外,它的性能很差,并且没有完全集成—请参阅,或者更简短地说:Get-Host。默认动词逻辑很吸引人,但模糊且脆弱,如您的示例所示。此外,它的性能很差,并且没有完全集成—请参阅