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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Run Expect scripts from managed code

Run Expect scripts from managed code

Scheduled Pinned Locked Moved C#
toolsquestionlearning
2 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.
  • I Offline
    I Offline
    inyoursadachine
    wrote on last edited by
    #1

    Hi, I need to run an Expect script (Expect for Windows of course) from managed code. By "run a script" I mean link (dynamically load) the Tcl and Expect libs (DLLs), create a Tcl_Interp and pass it the script to run. At a high level what does this involve? Can I load (at runtime) the Tcl and Expect DLLs from "unsafe" code? What's the best way to do this? TIA, Matt

    H 1 Reply Last reply
    0
    • I inyoursadachine

      Hi, I need to run an Expect script (Expect for Windows of course) from managed code. By "run a script" I mean link (dynamically load) the Tcl and Expect libs (DLLs), create a Tcl_Interp and pass it the script to run. At a high level what does this involve? Can I load (at runtime) the Tcl and Expect DLLs from "unsafe" code? What's the best way to do this? TIA, Matt

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      Technically, the CLR loads them. What you can do in C# (or in most managed languages) is P/Invoke the native functions, so long as the Tcl libs are resolvable (i.e., in the current process's current working directory - not the DLL's (though that may be the same as the process's current working directory) - or a directory in the PATH environment variable, the same as all executables in Windows). See the DllImportAttribute documentation in the .NET Framework SDK, as well as Consuming Unmanaged DLL Functions[^]. When you call a P/Invoke method, the CLR loads the native library, gets the proc, pushes your arguments on the stack, and executes the function. The return value is pushed on the stack (typically; depends on calling convention) and returned by the CLR to your managed code. So, you'll need to read the API documentation for Tcl. Chances are there'll be a setup function (to initialize the execution environment) and a function that will accept arguments (including the path to the Tcl script you want to execute). Getting the path to the Tcl script is easy: let the user specify it on the command line, using an OpenFileDialog, hard-code it (bad idea usually), or whatever.

      Microsoft MVP, Visual C# My Articles

      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