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.

 

posted @ 2016-07-22 16:29  Jeremy Wu  阅读(255)  评论(0编辑  收藏  举报