使 PowerShell 忽略分号 [英] Make PowerShell ignore semicolon

查看:91
本文介绍了使 PowerShell 忽略分号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 PowerShell 上执行一个 cmd 并且这个命令使用分号.然后 PowerShell 将其解释为多个命令.如何让 PowerShell 忽略分号并执行我的命令如何成为唯一的命令?

I want to execute a cmd on PowerShell and this command uses semicolons. Then PowerShell interprets it as multiple commands. How do I make PowerShell ignore the semicolons and execute my command how a unique command?

示例:

Invoke-Expression "msbuild /t:Build;PipelinePreDeployCopyAllFilesToOneFolder /p:Configuration=Debug;_PackageTempDir=$TargetFolder $WebProject"

另一个例子:

Invoke-Expression "test`;test2"

第二个示例响应:

The term 'test' 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:6
+ teste <<<< ;teste2
    + CategoryInfo          : ObjectNotFound: (teste:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

The term 'test2' is not recognized as the name of a cmdlet, function, script file, or operable program. Chec
k the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:13
+ teste;teste2 <<<<
    + CategoryInfo          : ObjectNotFound: (teste2:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

推荐答案

作为 Start-Process 的替代方案,您可以只调用命令,就像使用 cmd.exe 使用调用运算符 &:

As an alternative to Start-Process, you can just call the command as you would similarly call it using cmd.exe using the call operator &:

& msbuild /t:Build;PipelinePreDeployCopyAllFilesToOneFolder /p:Configuration=Debug;_PackageTempDir=$TargetFolder $WebProject

这篇关于使 PowerShell 忽略分号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆