Best practice for Invoke other scripts or exe in PowerShell

Recently, I find I used many different type method to invoke other scripts or exe in PowerShell. Maybe by start new process, or just use the call operator &. That's fine. But I want to mention there's one preper way to invoke other scripts or exe in PowerShell I'd like to use.

 

Problem background:

 I want to run msbuild to build something, but I want to sepcify multi folders. e.g. I want to output to both 'C:\output' and 'D:\output'. So, what should I do ?

 I may use the call operator & directly like:

 

What's wrong ? Can you find it ?

Actually, The real OutputFolder property value would be: "C:\output, D:\output". 

And the whole script will be tranlated to:

& .\msbuild.exe YOUR_PROJECT.csproj /t:$Targets /p:C:\output, D:\output

 

msbuild.exe will report something like, property is invalid or cannot distinguish and so on. Because the wired comma exists.

 

Sulotion:

 

Create a argument array, and use double quote to quote the property value to make true the quote will in the property value.

 

Done.

 

转载于:https://www.cnblogs.com/wushuaiyi/p/5695650.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值