如何使用字符串拆分器启动Process powershell.exe?

如何使用字符串拆分器启动Process powershell.exe?,powershell,intellisense,powershell-4.0,Powershell,Intellisense,Powershell 4.0,我想用这样的脚本块启动powershell.exe(工作正常): 但是这个脚本不起作用: Start-Process powershell.exe { $string = "123xAbcxEFG" $split1,$split2,$split3 = $string.Split("x") Write-Output $split1 Write-Output $split2 Write-Output $split3 sleep 10 } 我想我需要添加Type-Assemb

我想用这样的脚本块启动
powershell.exe
(工作正常):

但是这个脚本不起作用:

Start-Process powershell.exe {
  $string = "123xAbcxEFG"
  $split1,$split2,$split3 = $string.Split("x")
  Write-Output $split1
  Write-Output $split2
  Write-Output $split3
  sleep 10
}

我想我需要
添加Type-AssemblyName“SomeNameSpace”
,但是我如何才能找到那个名称空间呢?有intellisense之类的吗?

问题在于引号。如果你在双引号周围加上额外的单引号,它就会起作用。它也适用于三重双引号

Start-Process powershell.exe  {
$string = """123xAbcxEFG"""
$split1,$split2,$split3 = $string.split("""x""")
Write-Output $split1
Write-Output $split2
Write-Output $split3
sleep 10
}
我是如何更改代码以捕获错误的(没有附加双引号):


问题在于引用。如果你在双引号周围加上额外的单引号,它就会起作用。它也适用于三重双引号

Start-Process powershell.exe  {
$string = """123xAbcxEFG"""
$split1,$split2,$split3 = $string.split("""x""")
Write-Output $split1
Write-Output $split2
Write-Output $split3
sleep 10
}
我是如何更改代码以捕获错误的(没有附加双引号):


您可以使用启动作业,它实际上是启动新的powershell进程。你能做的很简单。 像这样:

$script= {get-help "dir"}
start-job -scriptblock $script
start-job 

您可以使用启动作业,它实际上是启动新的powershell进程。你能做的很简单。 像这样:

$script= {get-help "dir"}
start-job -scriptblock $script
start-job 

您可以使用启动作业,它实际上是启动新的powershell进程。你能做的很简单。像这样:

$script= {get-help "dir"}
start-job -scriptblock $script
start-job 
有关更多帮助,请使用:

get-help start-job

您可以使用启动作业,它实际上是启动新的powershell进程。你能做的很简单。像这样:

$script= {get-help "dir"}
start-job -scriptblock $script
start-job 
有关更多帮助,请使用:

get-help start-job

你能看到错误信息是怎么说的吗?它只是闪烁,然后关闭窗口,因为mei看不到错误。powershell窗口立即消失您能看到错误消息的内容吗?它只是闪烁,然后关闭窗口,因为mei看不到错误。powershell窗口立即消失我改变了答案,因为有几种方法。我还更新了我发现问题的方式。在方法调用中的第3行char:42+$split1,$split2,$split3=$string.split(x)+~Missing')。在第3行,char:42+$split1,$split2,$split3=$string.split(x)+~表达式或语句中意外的标记“x”。在第3行,在表达式或语句中,char:43+$split1、$split2、$split3=$string.split(x)+~意外标记“)”CategoryInfo:ParserError:(:)[],ParentContainerRorRecordException+FullyQualifiedErrorId:MissingendBranchisinMethodCall使用三重双引号查看我更改的答案。是的,因为此错误提示您引号未按预期工作。我更改了答案,因为有几种方法。我还更新了我发现问题的方式。在方法调用中的第3行char:42+$split1,$split2,$split3=$string.split(x)+~Missing')。在第3行,char:42+$split1,$split2,$split3=$string.split(x)+~表达式或语句中意外的标记“x”。在第3行,在表达式或语句中,char:43+$split1、$split2、$split3=$string.split(x)+~意外标记“)”CategoryInfo:ParserError:(:)[],ParentContainesErrorRecordException+FullyQualifiedErrorId:MissingendBranchisinMethodCall使用三个双引号查看我更改的答案。是的,因为此错误提示引号未按预期工作。