0
votes

I have a task where i have to run tabcmd commands from c# project, which will read the tableau reports from server and save into pdf file. I am using the following code to do it.

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();

When i run these tabcmd commands directly from Comman prompt they executed fine and pdf file is saved into my local directory, but when running through c# code the 2nd process starts but it never ends and not generating the required pdf file. The tabcmd command used is

tabcmd export "/Agency/AYR_CurrentYearAgencyIATA=0125452&:refresh=yes" --pdf --pagelayout landscape --pagesize legal --width 1600 -f "C:\Reports\StatusReport_CurrentYear_0125452.PDF"

1

1 Answers

0
votes

modify your code as below and test again:

        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() makes the current thread wait until the associated process terminates. It should be called after all other methods are called on the process. To avoid blocking the current thread, use the Exited event.
For getting more information see this link