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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Chinmay PatelChief Technical NinjaCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

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 PatelChief Technical NinjaCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.