Here is a .Net version of the program from
http://www.theswamp.org/index.php?topic=33994.0.
To the user, the only differences are environment variable expansion is not implemented for the application name, and return values from functions are in a list. For the .Net version handles and strings returned by the functions are wrapped in a list. The function parameters though do not want handles or strings in a list. So when passing a handle be sure to (car) it. This sample should give you an idea.
(setq handle (openshell "c:\\windows\\sysetem32\\cmd.exe" "\c sort")) ;; return nil on failure, an int in a list otherwise
(setq handle (car handle))
(writeshelldata handle "Once\nupon\na\ntime\n...\nzzz")
(setq sResult (readshelldata (car handle))) ;;
(closeshell (car handle))
(princ (car sResult))(princ)
It has been a couple years since I wrote any .Net code, and maybe 3 or 4 years since I wrote anything in .Net for Autocad. Doing this exercise came away with the following tidbits.
1. Took 5 hours and 15 minutes to implement (not that I was purposely keeping time).
2. Wasted about an hour trying to get the commands to run in Autocad. Problem turned out to be having "Copy Local" to true for AcDbMgd and AcMgd references.
3. Wasted about an hour looking up ResultBuffer issues for the [LispFunction] attribute. Luckily ran across this link,
http://forums.autodesk.com/t5/NET/Return-type-of-object-is-LispFunction-now-fails/m-p/2217766/highlight/true#M100524. Wrote 2 versions as a standalone app last night (not part of the 5h15m time period). The first version was pretty much a 1:1 conversion with DllImports up the, and lots of ugly code. Then I found a reference to the System.Diagnostic.Process api and the second version using it took like 20 minutes to write.
5. How are RTNORM, RTERR, RTNONE, RTLONG, etc. handled in .Net. Is there something to import? I just grabbed the items in adscodes.h and put them in ResultCodes.cs, but this seems heavy handed.
6. When dealing with ResultBuffers, is it customary to convert them into array prior to working with their contents?
7. Dealing with the ResultBuffers took bit of code thrashing, and it was easily 2 hours to write the public ResultBuffer OpenShell(ResultBuffer args) routine. After that each one was simple and took just a couple minutes.
8. Whole lot less boiler plate code to write in C# and faster to code (when not dealing with learning issues).