Link to home
Start Free TrialLog in
Avatar of Mark01
Mark01Flag for United States of America

asked on

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:
User generated imageThe 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

Avatar of Kimputer
Kimputer

psi.Arguments = "-e " + "\"" + Argu2 + " " + Argu3 + " " + Argu4 + "\"";

Open in new window

Avatar of Mark01

ASKER

@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

ASKER CERTIFIED SOLUTION
Avatar of Chinmay Patel
Chinmay Patel
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mark01

ASKER

@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

Avatar of Mark01

ASKER

Thank you, Chinmay Patel and Kimputer.
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 :)
Avatar of Mark01

ASKER

Thank you for the pointers, Chinmay.