本文介绍了从Windows App向Consol App C#传递多个CommandLine参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,

我有一个问题,我正在使用Windows应用程序,该应用程序使用ProcessStartInfo()方法调用控制台应用程序.我必须将5个命令行参数从Widows应用程序传递到控制台应用程序,但是我遇到了一些问题.
控制台应用程序给出异常"输入字符串的格式不正确".


当我调试此Windows应用程序并获取参数并手动从命令提示符运行控制台应用程序时,这将提供正确的输出.

下面是代码:

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:

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

推荐答案



这篇关于从Windows App向Consol App C#传递多个CommandLine参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 22:05