Click here to Skip to main content
16,022,846 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello Friends,

I have a problem, I'm working on windows application which calls a console application using ProcessStartInfo() Method. I have to pass 5 Command line arguments from Widows application to Console application but I am having some problem.
The console app gives exception "Input string is not in the correct format".


when I debug this Windows application and gets the arguments and runs the console application from command prompt manually this gives correct output.

below is the code:
C#
string cmdexePath = @"D:\SortProgram\SortProgram\Executable\TS_PD.exe";
            //notice the quotes around the below string...
            string myApplication = cmdexePath + "  " + "D:\\SortedFile.txt D:\\FixFormat.txt "+ " " + GlobalClass.Global.DetPath + "  " + MergeFields +" 10000";
            //the /K keeps the CMD window open - even if your windows app closes
           // string cmdArguments = String.Format("/K {0}", myApplication);
            string cmdArguments = myApplication;
            System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(cmdexePath,cmdArguments);
            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo = psi;
            p.Start();
Posted
Updated 27-Jan-11 19:34pm
v3

We cannot see the values that you pass as command line.

However, this[^] may help you out.
 
Share this answer
 
This is wonderful! Who cares what your "windows application" does?
What does matter is what your "TS_PD.exe" does. It can do anything, accept or deny command line, whatever. I wonder how you even hope to get any answer if you provide no information on your console application.

By the way, if -- by any chance -- you have a source code for TS_PD.exe, running this application makes no sense at all. In this case, you should use the code as a library or even add it to your "windows application".

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900