C# Process Object Argument Error

I am trying to use Process object argument variables, but the application (Visual Cut) will not export the report. Please help me resolve the errors.


With the following, Visual Cut only starts and opens the grid:
        private void btnOpenPDF_Click(object sender, EventArgs e)
        {
            string Argu1 = "-e";
            string Argu2 = "C:\\test_3\\People_1.rpt";
            string Argu3 = "Export_Format:Adobe Acrobat (pdf)";
            string Argu4 = "Export_File:C:\\test_3\\People_1.pdf";
            Process p = new Process();
            ProcessStartInfo psi = new ProcessStartInfo();
            psi.UseShellExecute = true;
            psi.FileName = "C:\\Program Files (x86)\\Visual CUT 11\\Visual CUT.exe";
            psi.Arguments = 34 + Argu1 + " " + Argu2 + " " + " " + Argu3 + " " + Argu4 + "";
            p.StartInfo = psi;
            p.Start();

Open in new window

following get a Visual Cut "Failed: Command Line Argument not in Double Quotes" error:
        private void btnOpenPDF_Click(object sender, EventArgs e)
        {
            string Argu1 = "-e";
            string Argu2 = "C:\\test_3\\People_1.rpt";
            string Argu3 = "Export_Format:Adobe Acrobat (pdf)";
            string Argu4 = "Export_File:C:\\test_3\\People_1.pdf";
            Process p = new Process();
            ProcessStartInfo psi = new ProcessStartInfo();
            psi.UseShellExecute = true;
            psi.FileName = "C:\\Program Files (x86)\\Visual CUT 11\\Visual CUT.exe";
            psi.Arguments = "-e " + "" + Argu2 + " " + " " + Argu3 + " " + Argu4 + "";
            p.StartInfo = psi;
            p.Start();
        }

Open in new window

With the following, Visual Cut only starts and opens the grid:
        private void btnOpenPDF_Click(object sender, EventArgs e)
        {
            string Argu1 = "-e";
            string Argu2 = "C:\\test_3\\People_1.rpt";
            string Argu3 = "Export_Format:Adobe Acrobat (pdf)";
            string Argu4 = "Export_File:C:\\test_3\\People_1.pdf";
            Process p = new Process();
            ProcessStartInfo psi = new ProcessStartInfo();
            psi.UseShellExecute = true;
            psi.FileName = "C:\\Program Files (x86)\\Visual CUT 11\\Visual CUT.exe";
            psi.Arguments = "" + Argu2 + "-e " + "" + Argu3 + " " + Argu4 + "";
            p.StartInfo = psi;
            p.Start();

Open in new window

Here is a build error:
Build ErrorThe following works:
        private void btnOpenPDF_Click(object sender, EventArgs e)
        {
            Process p = new Process();
            ProcessStartInfo psi = new ProcessStartInfo();
            psi.UseShellExecute = true;
            psi.FileName = "C:\\Program Files (x86)\\Visual CUT 11\\Visual CUT.exe";
            psi.Arguments = "-e \"C:\\test_3\\People_1.rpt\" \"Export_Format:Adobe Acrobat (pdf)\" \"Export_File:C:\\test_3\\People_1.pdf\"";

            p.StartInfo = psi;
            p.Start();
        }

Open in new window

Mark01Asked:
Who is Participating?
 
Chinmay PatelConnect With a Mentor Enterprise ArchitectCommented:
Hi Mark01,

I made some changes in your code block, kindly give it a try and let me know

 string command = "-E";
            string reportName = "\"C:\\test_3\\People_1.rpt\"";
            string parameters = "\"Export_Format:Adobe Acrobat (pdf)\"";
            string fileName = "\"Export_File:C:\\test_3\\People_1.pdf\"";
            Process p = new Process();
            ProcessStartInfo psi = new ProcessStartInfo();
            psi.UseShellExecute = true;
            psi.FileName = "C:\\Program Files (x86)\\Visual CUT 11\\Visual CUT.exe";
            psi.Arguments = string.Concat(command, " ", reportName, " ", parameters, " ", fileName);

Open in new window


Regards,
Chinmay.
0
 
KimputerCommented:
psi.Arguments = "-e " + "\"" + Argu2 + " " + Argu3 + " " + Argu4 + "\"";

Open in new window

0
 
Mark01Author Commented:
@Kimputer: I get a Visual Cut "Requested Report File Name does not exist (C:\test_3\People_1.rpt Export_Format:Adobe Acrobat (pdf) Export_File:C:\test_3\People_1.pdf)" error. Code:
        private void btnOpenPDF_Click(object sender, EventArgs e)
        {
            string Argu1 = "-e";
            string Argu2 = "C:\\test_3\\People_1.rpt";
            string Argu3 = "Export_Format:Adobe Acrobat (pdf)";
            string Argu4 = "Export_File:C:\\test_3\\People_1.pdf";
            Process p = new Process();
            ProcessStartInfo psi = new ProcessStartInfo();
            psi.UseShellExecute = true;
            psi.FileName = "C:\\Program Files (x86)\\Visual CUT 11\\Visual CUT.exe";
            psi.Arguments = "-e " + "\"" + Argu2 + " " + Argu3 + " " + Argu4 + "\"";
            p.StartInfo = psi;
            p.Start();

Open in new window

0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
Mark01Author Commented:
@Chinmay Patel: Your code worked. The report exported. Full code:
        private void btnOpenPDF_Click(object sender, EventArgs e)
        {
            string command = "-E";
            string reportName = "\"C:\\test_3\\People_1.rpt\"";
            string parameters = "\"Export_Format:Adobe Acrobat (pdf)\"";
            string fileName = "\"Export_File:C:\\test_3\\People_1.pdf\"";
            Process p = new Process();
            ProcessStartInfo psi = new ProcessStartInfo();
            psi.UseShellExecute = true;
            psi.FileName = "C:\\Program Files (x86)\\Visual CUT 11\\Visual CUT.exe";
            psi.Arguments = string.Concat(command, " ", reportName, " ", parameters, " ", fileName);
            p.StartInfo = psi;
            p.Start();

Open in new window

0
 
Mark01Author Commented:
Thank you, Chinmay Patel and Kimputer.
0
 
Chinmay PatelEnterprise ArchitectCommented:
Thanks Mark01 :)

Couple of pointers in case you want to deal with launching other processes using command line
1. Study command line of the app - that is what I did. I know we both have been working on this for last 1-2 days :) so I studied Visual Cut's command line options. So they have explicitly mention that each command has to be quoted in double quotes. That is what I changed.
2. Understand escape sequence - ' " \ are couple of special characters and different languages interpret them differently. VB handles them very easily but C# can be tricky.

All the best :)
0
 
Mark01Author Commented:
Thank you for the pointers, Chinmay.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.