从Windows App向Consol App C#传递多个CommandLine参数 [英] Passing multiple CommandLine argumrnts from Windows App To Consol App C#

查看:114
本文介绍了从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应用程序"做什么?
重要的是您的"TS_PD.exe"的作用.它可以执行任何操作,接受或拒绝命令行.我想知道如果您在控制台应用程序上没有提供任何信息,您甚至希望得到什么答案.

顺便说一句,如果有任何可能-您有TS_PD.exe的源代码,则运行此应用程序根本没有任何意义.在这种情况下,您应该将代码用作库,甚至将其添加到"Windows应用程序"中.

—SA
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


我们看不到您作为命令行传递的值.

但是, [
We cannot see the values that you pass as command line.

However, this[^] may help you out.


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆