C# Process.Start()不';从C运行tabcmd命令时,无法完成#

C# Process.Start()不';从C运行tabcmd命令时,无法完成#,c#,cmd,tableau-api,process.start,C#,Cmd,Tableau Api,Process.start,我有一个任务,我必须从c#project运行tabcmd命令,它将从服务器读取tableau报告并保存到pdf文件中。我使用下面的代码来完成它 string reportPath = "/Agency/AYR_CurrentYearAgencyIATA=0125452&:refresh=yes"; string currentYearPdf = @"C:\Reports\StatusReport_CurrentYear_0125452.PDF"; System.Diagnostics.P

我有一个任务,我必须从c#project运行tabcmd命令,它将从服务器读取tableau报告并保存到pdf文件中。我使用下面的代码来完成它

string reportPath = "/Agency/AYR_CurrentYearAgencyIATA=0125452&:refresh=yes";
string currentYearPdf = @"C:\Reports\StatusReport_CurrentYear_0125452.PDF";
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.WorkingDirectory = @"C:\tabcmd\Command Line Utility\";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = false;
process.StartInfo.RedirectStandardOutput = false;
process.StartInfo.RedirectStandardError = false;
process.StartInfo.Arguments = "/C tabcmd login -s http://prodtableau -u xxx -p xxx";
process.Start();
process.StartInfo.Arguments = "'/C tabcmd export \"" + reportPath + "\"" +
    " --pdf --pagelayout landscape--pagesize legal --width 1600 -f \"" + currentYearPdf +
     "\"'";
process.Start();
当我直接从Comman提示符运行这些tabcmd命令时,它们执行得很好,pdf文件保存到我的本地目录中,但当运行c#code时,第二个过程开始,但永远不会结束,并且不会生成所需的pdf文件。 使用的tabcmd命令是

tabcmd export“/Agency/AYR\u CurrentYearAgencyIATA=0125452&:refresh=yes”--pdf--pagelayout横向布局--pagesize legal--width 1600-f“C:\Reports\StatusReport\u CurrentYear\u 0125452.pdf”


按如下所示修改代码并再次测试:

        process.StartInfo.Arguments = "/C tabcmd login -s http://prodtableau -u xxx -p xxx";
        process.Start();

        process.WaitForExit()

        process.StartInfo.Arguments = "'/C tabcmd export \"" + @reportPath + "\"" + " --pdf --pagelayout landscape--pagesize legal --width 1600 -f \"" + @currentYearPdf + "\"'";
        process.Start();

        process.WaitForExit()
WaitForExit()使当前线程等待相关进程终止。应该在进程上调用所有其他方法之后调用它。要避免阻塞当前线程,请使用Exited事件。

有关更多信息,请参见此

@venky您可以创建一个新流程。你为什么不这样做?这两种方式都不起作用。请检查我的process.Startinfo.Arguments是否与下面的命令匹配>tabcmd export“/Agency/AYR\u CurrentYearAgencyIATA=0125452&:refresh=yes”--pdf--pagelayout横向布局--pagesize legal--width 1600-f“C:\Reports\StatusReport\u CurrentYear\u 0125452.pdf”@venky这似乎是真的。也许quot符号是个问题