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.
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步