问题描述
我真正想要做的就是这个。
静态字符串的主要(字串[] args)
但是,这并不正常工作,你唯一的选择是无效
和 INT
。那么,有哪些不同的方式来回报,我需要返回到调用应用程序的字符串?
背景
我需要编写专门从另一个应用程序调用一个控制台应用程序
的Process.Start(MyCode.exe -Option 12aaa1234);
这调用程序怎样才能收到一个字符串从可执行回来了?
研究
据我所知,在这个时间点我唯一的选择是让调用应用程序在开始之前,附上一个监听流过程的标准输出流,并从我的可执行文件中发送回归使用Console.Out.Write。这其实是做的唯一方法,或者是有什么不同/更好,我可以使用?
This isn't the only way to do this, but it is the most common.
The other options would involve some form of interprocess communication, which is likely going to be significantly more development effort for a single string.
Note that, if the calling application is a .NET application, and you have control over both applications, it might make more sense to just write a class library instead of a console application. This would allow you to keep the code completely separate, but have the executable "call into" your library to get the string data.
这篇关于从控制台应用程序返回一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!