执行外部程序 [英] exeute external program

查看:92
本文介绍了执行外部程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好,下午好,晚上好,无论您在哪里,

我编写了一个小应用程序,该程序执行旧的dos程序bascom,link和lib.
我做到了"因为我必须处理一些旧的基本程序,而这可能相当
Windows很讨厌,因为开发工具不支持文件路径.
由于一切正常,我决定集成debug.exe的执行,但这根本不起作用.
启动该过程将在dosbox中执行debug,但是不显示任何提示(这是-),并且不显示任何我正在输入的内容.
当我单击浏览器中的debug一切正常时,为什么c#进程不起作用?

有什么想法吗?

franz

good morning, good afternoon, good evening whereever you are,

i''ve written a small application which executes the old dos-programs bascom, link and lib.
i did it ''cause i have to work over some old basic programs and that can be quite
nasty with windows, because the development tools didn''t support filepathes.
as all worked fine i decided to integrate the execution of debug.exe and that doesn''t work at all.
starting the process executes debug within the dosbox, but shows no prompt (which is this : -) and shows nothing i''m typing.
when i click debug in the explorer everthing''s ok, so why doesn''t c# process work ?

any ideas ?

franz

推荐答案

首先,除非您谈论的不是基于NT的过时系统,否则不存在"dosbox"和旧的dos程序"之类的东西.还有一些其他事情:…因为开发工具不支持文件路径" –谁告诉过你?

您在说的只是一个控制台应用程序.我敢打赌,这是一个普通的Windows 32位或64位应用程序,几乎没有DOS.现在,难怪您没有提示符或类似的提示,除非您没有在控制台中编写它.如果您希望没有控制台的常规控制台输入,则必须以某种方式进行模拟.为此,您需要使用System.Diagnostics.Process.Start(ProcessStartInfo),重定向StandardInput流并将调试器或其他工具的每个步骤上的输入数据写入此流.要获得输出,您还需要重定向StandardOutputStandardError.这不是那么简单.

参见:
http://msdn.microsoft.com/en-us/library/system.diagnostics. process.aspx [^ ],
http://msdn.microsoft.com/en-us/library/system. diagnostics.process.standardinput.aspx [ ^ ](此处为一些代码示例),
http://msdn.microsoft.com/en-us/library/system. diagnostics.process.standarderror.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system. diagnostics.process.standardoutput.aspx [ ^ ](和此处),
http://msdn.microsoft.com/en-us/library/system.diagnostics. processstartinfo.aspx [ ^ ].

—SA
To start with, there is not such thing as "dosbox" and "old dos-programs" unless you are talking about obsolete systems not based on NT. Something else: "…because the development tools didn''t support filepathes" — who told you so?

What are you talking about is just a console application. I bet this is a regular Windows 32- or 64-bit application, without a tiny bit of DOS. Now, no wonder that you don''t have a prompt or anything like that unless you don''t write it in your console. If you want the regular console input without console, you have to emulate it somehow. To do so, you need to use System.Diagnostics.Process.Start(ProcessStartInfo), redirect StandardInput stream and write your input data into this stream on every step of debugger or other tool. To get output, you will need to redirect StandardOutput and StandardError as well. This is not so simple.

See:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx[^],
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardinput.aspx[^] (some code sample here),
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standarderror.aspx[^],
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx[^] (and here),
http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.aspx[^].

—SA


此代码段是从此处提取的:
http://stackoverflow.com/questions/186822/capturing-console-从"-net-application-c输出" [ ^ ]


显示ping命令的输出:
This code snippet which was extracted from here :
http://stackoverflow.com/questions/186822/capturing-console-output-from-a-net-application-c[^]


shows the output of a ping command :
Process compiler = new Process();
compiler.StartInfo.FileName = "ping.exe";
compiler.StartInfo.Arguments = "localhost";
compiler.StartInfo.UseShellExecute = false;
compiler.StartInfo.RedirectStandardOutput = true;
compiler.Start();

Console.WriteLine(compiler.StandardOutput.ReadToEnd());

compiler.WaitForExit();




我认为您只需进行很少的操作就可以使它适应您的问题.

希望对您有所帮助.




I think you can adapt it to your problem with a very little manipulation.

Hope it helps.


这篇关于执行外部程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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