我已經看過這個代碼片段,但不能完全弄清楚爲什麼它可以成功運行。這個參數是如何在C#中傳遞的?
class Program
{
public static void Main()
{
var startInfo = new ProcessStartInfo
{
FileName = "PowerShell.exe",
Arguments = @"-NoLogo -NoProfile ""Get-Content Queries.txt"" | Set-Content Output.tsv"
};
Console.WriteLine(startInfo.Arguments);
Process.Start(startInfo);
}
}
如果我嘗試直接在命令執行powershell -NoLogo -NoProfile "Get-Content Queries.txt" | Set-Content Output.tsv
提示它會拋出錯誤消息,但上面的代碼片段可以成功完成。
如何處理代碼中的雙引號?
嘗試提供Queries.txt的完整路徑 – cheedep
@cheedep執行此操作時收到的錯誤消息是'Set-Content'不被識別爲內部或外部命令, 可操作程序或批處理文件。所以我認爲它與命令參數解析相關,而不是輸入文件的相對位置。 – derekhh
相當於你在命令行上用C#做的事情是'powershell'-NoLogo -NoProfile「」Get-Content Queries.txt「」| Set-Content Output.tsv「' –