从我们的应用程序中调用编译器 [英] invoking compiler from our application
问题描述
我正在c#中实现多语言代码编辑器.当用户按下编译器按钮在编辑器中键入程序后,c编译器应将文本区域中键入的程序(c程序)作为输入&应该返回其对象,该对象将包含相应的输出(输出或错误,如果有的话).
1)首先如何调用c编译器或将其链接到我们的c#程序?
2)然后如何进行上述场景?
3)如何捕捉c编译器给出的输出?
请针对以上问题提出解决方案.
关于,
thimmanagouda patil
I am implementing multilanguage code editor in c#.after typing program in editor when user presses compiler button,c compiler should take program typed(c program) in text area as input & should return its object that will contains corresponding output(output or error if any) .
1) firstly how to call or link c compiler to our c# program?
2)then how to carried out above scenerio?
3) how to catch output given by c compiler?
please suggest solution to above stuff.
with regards,
thimmanagouda patil
推荐答案
看看我对类似问题的回答: ^ ].
这里的关键是从生成的进程中捕获stdout
和stderr
中的编译器输出.我在我的答案中解释了它.您可以重新定向流,并在编译器不工作时在永久工作且正在休眠的线程中准备它(准确地模式,等待阻塞流读取操作).线程每次读取输出或错误的某个单位时,是否应通知UI.
您不能通过线程使用UI控件进行操作.而是应使用System.Windows.Forms.Control
(仅适用于Forms)或System.Windows.Threading.Dispatcher
(对Forms和WPF都适用)的Invoke调用必需的方法.我在这里描述了所有详细信息: Control.Invoke()与Control.BeginInvoke( ) [ ^ ].另请参见 Treeview Scanner和MD5问题 [ ^ ].
对于线程,我建议使用其他答案,该答案建议创建一个线程包装器,以在避免类型转换的情况下将参数传递给线程: ^ ].
-SA
Look at my Answer to similar question: providing COMPILER, DEBUGGER facility in IDE[^].
A key here is to catch compiler output instdout
andstderr
from the process you spawn. I explained it in my Answer. You can re-direct the stream and ready it in some thread which is permanently working and is sleeping (mode exactly, waiting at the blocking stream read operation) when compiler is not working. Every time the thread read some unit of output or error, if should notify UI.
You cannot operate with UI controls from the thread. Instead, you should use Invoke of Invoke required methods ofSystem.Windows.Forms.Control
(Forms only) orSystem.Windows.Threading.Dispatcher
(good for both Forms and WPF). I described all the details here: Control.Invoke() vs. Control.BeginInvoke()[^]. See also Problem with Treeview Scanner And MD5[^].
For thread, I recommend use my other Answer which advised to create a thread wrapper for passing parameters to the thread while avoiding type casting: How to pass ref parameter to the thread[^].
—SA
看看 ^ ]中有关如何实现此功能的一些文章和建议.
Take a look here[^] for some articles and suggestions on how to implement this.
这篇关于从我们的应用程序中调用编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!