Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
I am developing an IDE for autoit in vb.net. Now i am practicing how to run my scripts from my new IDE. I have successully ran some one or two line scripts. But when i run scripts using any kind of loops, i can't print the result in output console. The code in the script is to write a specific text into the console in every 5 seconds. When i click the run button, the script is running, but nothing is displaying in output console. This is my vb.net code
VB
Private Sub BTN_Run_Click(sender As Object, e As EventArgs) Handles BTN_Run.Click

        Dim AutoitCmd As String = "C:\Program Files\AutoIt3\Autoit3.exe "
        Dim path As String = Application.StartupPath
        Dim tempName As String = "\Untitled.au3"
        Dim Filename As String = path & tempName

        Dim procID As Integer
        Dim Proc As New Process
        Proc.StartInfo.FileName = AutoitCmd
        Proc.StartInfo.Arguments = """" & Filename & """"
        Proc.StartInfo.CreateNoWindow = True
        Proc.StartInfo.UseShellExecute = False
        Proc.StartInfo.RedirectStandardOutput = True
        Proc.Start()
        
        procID = Proc.Id
        Dim outrd As StreamReader = Proc.StandardOutput
        Dim out As String = outrd.ReadToEnd

        cc1.WriteOutput("==> " & out, Color.GreenYellow)
        Proc.WaitForExit()
        If Proc.HasExited = True Then
            Proc.Close()
        Else
            cc1.WriteOutput("==> Running" & Filename, Color.GreenYellow)
        End If
    End Sub


What I have tried:

What i have tried
1. Made a gui with ScintillaNet control.
2. Choose appropriate lexer in that control so that my code editor recognizes autoit code.
3. I have tried with Procress.Start method in vb.net. see the code i have included in my post.
Posted
Updated 6-Jun-16 6:13am

1 solution

You need to use CodeDOM.

Now, what you would do with it? If you want to execute some of its code from your host application, you would need to define some interface known to both host application and the application to be built, so you have to reference some assembly with appropriate API, which should better be the definition of some interfaces which I usually call "plug-in interface". Then you can use the assembly build via .NET reflection.

But let's make one step at a time. First you need to learn CodeDOM. This topic is pretty simple. You can start here: Using the CodeDOM[^].

Now, about using the assembly you build from the user's code via reflection: please see my past answers:
Dynamically Load User Controls[^],
C# Reflection InvokeMember on existing instance[^],
code generating using CodeDom[^] (again, on CodeDOM).

But now, we are coming to the more difficult problem. The problem is: if a user can write code and compile the assembly and then load it in the process's memory, it can be done again and again. And it will create a memory leak. In .NET, there are no a way to unload a loaded assembly (the reasons are pretty obvious, safety, but it's not so easy to explain it; please see my past answers referenced below). The only way to unload some code is to create an extra application domain and later unload it with all its assemblies. But it means that your compiled assembly (plug-in) should be in this separate application domain and communicate with your host via IPC (application domains work in isolated address spaces).

This is all solvable, but you have to learn all related techniques. Please see the rest of my past answers on the topic, all referenced in this one: Access a custom object that resides in plug in dll[^].

I do have a sample application doing all that, but it is not yet published.

—SA
 
Share this answer
 
Comments
Vinod Kc 6-Jun-16 13:39pm    
@Sergey Alexandrovich,
Autoit has it's own interpreter to run the script. I think i don't need the CodeDom. Please forgive me if it is wrong. I just want to run the interpreter with proper command line switches. And i have succeeded but when it's come to script which contains loops, i can't get the output. That's the problem.
Sergey Alexandrovich Kryukov 6-Jun-16 17:10pm    
No problem. I just want to say that code in a .NET language is not script, but forgot to mention it.
If this is your own script processor, and you really need it, do it you way, but note that you can use any .NET language as well, compile it, see the compilation errors and fix them and so on.

If this is your own interpreter, you should know better how to run it. Interpreter is interpreted, it should not be a separate application which you just run with the command line. You have to embed it in the application, pretty much like JavaScript is embedded in browser. In other words, you need to provide interpreter's interface to the host application. It's all you need to design. From your question, it's not even clear how your interpreter can possibly work; so far, it sounds like a compiler or stand-along command-line interpreter, or something...

—SA
Vinod Kc 7-Jun-16 1:01am    
@SA,
Thanks for the reply. I don't know anything about the technical details of that interpreter. All i know is, i can run any scripts without loops and i can display its output to the user. But if try to run scripts which contain loops,it is running but i can't display output. So i think i did something wrong in the process.Start.
Sergey Alexandrovich Kryukov 7-Jun-16 1:07am    
Sorry, I don't understand. You say that you already have your own interpreter. How can you possibly be unaware of its technical detail? Maybe you simply don't have anything suitable?
—SA
Vinod Kc 7-Jun-16 1:15am    
I mean i don't kow if it is a stand alone or something like that.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900