With string interpolation, how do you handle variables piped into a command that contain spaces in them? For example, if you have a variable that has spaces in it (like a UNC path), how do you handle that?
This code works when no spaces are present in the "filePath" variable (i.e.; ServerName estfile.txt):
System.Diagnostics.Process.Start("net.exe", $"use X: \{filePath} {pwd /USER:{usr}").WaitForExit();
As soon as you encounter a path that has spaces in it, however, the command above no longer works, because it's unable to find the path. Normally, I would apply quotes around a path containing spaces, to counter this (in other languages like PowerShell). How do you do something similar with C# interpolation.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…