Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Redirect Console for In-Memory Execution

Redirect Console for In-Memory Execution

Scheduled Pinned Locked Moved C#
tutorialquestioncomtoolsperformance
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anindya Chatterjee
    wrote on last edited by
    #1

    Hi, I am developing a scripting tool in which I want to compile and execute the code in MEMORY, not as an executable file. But in there I need to redirect the console output to a Richtextbox and input to a simple textbox. Example: The script code is like this

    public class Script
    {
    public static void Main()
    {
    Console.WriteLine("Hello World");
    Console.ReadKey();
    }
    }

    When I compile and execute in memory I want to print "Hello World" in a richtextbox and input the key from a textbox to terminate the application. How can I accomplish it? I know how to redirect input/output if it is an executable file, but I don't know how to do the same for in-memory execution. Can anyone please help me?

    Anindya Chatterjee -------------------------------------------------------- 1. Don't Visit ..[^] 2. But Watch ..

    N 1 Reply Last reply
    0
    • A Anindya Chatterjee

      Hi, I am developing a scripting tool in which I want to compile and execute the code in MEMORY, not as an executable file. But in there I need to redirect the console output to a Richtextbox and input to a simple textbox. Example: The script code is like this

      public class Script
      {
      public static void Main()
      {
      Console.WriteLine("Hello World");
      Console.ReadKey();
      }
      }

      When I compile and execute in memory I want to print "Hello World" in a richtextbox and input the key from a textbox to terminate the application. How can I accomplish it? I know how to redirect input/output if it is an executable file, but I don't know how to do the same for in-memory execution. Can anyone please help me?

      Anindya Chatterjee -------------------------------------------------------- 1. Don't Visit ..[^] 2. But Watch ..

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      What is the benefit you are seeking by compiling and executing in memory? Does it outweigh the risks of potential security vulnerabilities this exposes? If this needed, why compile an entire application, just use the particular method that is necessary for your functionality.


      only two letters away from being an asset

      A 1 Reply Last reply
      0
      • N Not Active

        What is the benefit you are seeking by compiling and executing in memory? Does it outweigh the risks of potential security vulnerabilities this exposes? If this needed, why compile an entire application, just use the particular method that is necessary for your functionality.


        only two letters away from being an asset

        A Offline
        A Offline
        Anindya Chatterjee
        wrote on last edited by
        #3

        That is not the point. OK instead of in-memory execution I invoke the entry point function from the compiled assembly. But there also how would I redirect the console input output to a textbox or richtextbox?

        Anindya Chatterjee -------------------------------------------------------- 1. Don't Visit ..[^] 2. But Watch ..

        N 1 Reply Last reply
        0
        • A Anindya Chatterjee

          That is not the point. OK instead of in-memory execution I invoke the entry point function from the compiled assembly. But there also how would I redirect the console input output to a textbox or richtextbox?

          Anindya Chatterjee -------------------------------------------------------- 1. Don't Visit ..[^] 2. But Watch ..

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          Anindya Chatterjee wrote:

          how would I redirect the console input output to a textbox or richtextbox?

          You don't. Execute the method from the assembly, get the output, then assign it to the textbox in your application.


          only two letters away from being an asset

          A 1 Reply Last reply
          0
          • N Not Active

            Anindya Chatterjee wrote:

            how would I redirect the console input output to a textbox or richtextbox?

            You don't. Execute the method from the assembly, get the output, then assign it to the textbox in your application.


            only two letters away from being an asset

            A Offline
            A Offline
            Anindya Chatterjee
            wrote on last edited by
            #5

            Sorry, I didn't get that. If the script has a line like:

            Console.WriteLine("Hello World");

            then how would I get the output and assign to the textbox? That entry-point function is not returning any string. If I am wrong please correct me with some example. And also what about Console.ReadKey() or Console.ReadLine(...) ? Thanks and regards,

            Anindya Chatterjee -------------------------------------------------------- 1. Don't Visit ..[^] 2. But Watch ..

            N 1 Reply Last reply
            0
            • A Anindya Chatterjee

              Sorry, I didn't get that. If the script has a line like:

              Console.WriteLine("Hello World");

              then how would I get the output and assign to the textbox? That entry-point function is not returning any string. If I am wrong please correct me with some example. And also what about Console.ReadKey() or Console.ReadLine(...) ? Thanks and regards,

              Anindya Chatterjee -------------------------------------------------------- 1. Don't Visit ..[^] 2. But Watch ..

              N Offline
              N Offline
              Not Active
              wrote on last edited by
              #6

              That's the point you can't do this. And why would you want to? If you have a textbox in your application and you need to pass the value from the textbox to an external application, then why do you need to try reassigning the input stream? Sounds more like you need to refactor the external application.


              only two letters away from being an asset

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups