Author Topic: WScript and Autolisp  (Read 5131 times)

0 Members and 1 Guest are viewing this topic.

pkohut

  • Guest
WScript and Autolisp
« on: July 01, 2010, 08:36:20 AM »
I've seen a couple samples of the 2 being used together but they were fairly basic.  Can redirection and output piping be done? How about retrieving the results sent to stdout?

TIA

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Re: WScript and Autolisp
« Reply #1 on: July 01, 2010, 09:06:03 AM »
> retrieving results.
Nope (well i dont know how).

> redirection and output piping.
Not sure what that is.

We dont get much to work with really. Sure there are plenty of things we can do but in the grand scheme of things we are locked down pretty good.

eg:
Code: [Select]
(vlax-dump-object (vlax-create-object "WScript.Shell") T)

; IWshShell3: Shell Object Interface
; Property values:
;   CurrentDirectory = ...Indexed contents not shown...
; Methods supported:
;   Exec (2)
 
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

pkohut

  • Guest
Re: WScript and Autolisp
« Reply #2 on: July 01, 2010, 10:22:56 AM »
> retrieving results.
Nope (well i dont know how).

> redirection and output piping.
Not sure what that is.

We dont get much to work with really. Sure there are plenty of things we can do but in the grand scheme of things we are locked down pretty good.

Things like this done in cmd.exe -
Code: [Select]
dir | sort
            or
sort TextDoc.txt > SortedDoc.txt

or some of the more advanced like combining 2 commands on the same line with &&. There also ways, using cmd, to redirect the stdin stdout and stderr streams. It doesn't have all the power of a Bourne Shell, but some trick stuff can be done.

I've been reading "The Art of Unix Programming" for the past week or so and it's been very enlightening and a great read.  So 2 days ago, based on my new found enlightenment, I began playing around with some Autolisp extensions (ADS) and then saw the blerp about WScipt in another thread this morning.

So, the extensions consists of 4 commands,  openshell  closeshell  readshelldata and writeshelldata.
Useage is something like this to read from stdout
Code: [Select]
(setq handle (openshell "c:\\windows\\system32\\cmd.exe" "/c dir | sort"))
(while (/= nil (setq s (readshelldata handle))(princ s))(princ) ;; read the stream and print the results until there is nothing left in the stream
(closeshell handle)
the writeshelldata command isn't written yet, but the idea is your writing to stdin which in the inputs or stdin to other streams.
Code: [Select]
(setq handle (openshell "c:\\windows\\system32\\cmd.exe" "/c sort"))
;; for each item in a list, write to stdin which is directed to the sort routine
(foreach e '("Just" "a" "sample" "list") (writestreamdata handle e))
(while (/= nil (setq s (readshelldata handle))(princ s))(princ) ;; read the sorted items.
(closeshell handle)

Combine this with your own bat files, python code, whatever you can think of, how about these http://gnuwin32.sourceforge.net/packages.html. I think it could be quite useful.  Anyways, 2 days of coding and 2 versions already. Stuff is working but not polished and there are a couple implementation details to still figure out.  I'll try and get something released in the next day or two.  :-)

highflyingbird

  • Bull Frog
  • Posts: 415
  • Later equals never.
Re: WScript and Autolisp
« Reply #3 on: July 01, 2010, 10:42:36 AM »
I've seen a couple samples of the 2 being used together but they were fairly basic.  Can redirection and output piping be done? How about retrieving the results sent to stdout?

em,What a good idea! I know few about WScript.  just watching. Can WScript put C++ and Lisp together?

http://bbs.mjtd.com/dispbbs.asp?boardID=3&ID=62386&page=1
http://bbs.mjtd.com/dispbbs.asp?boardid=3&replyid=68044&id=62106&page=1&skin=0&Star=1

here are two articles about JScript and VBscript to Lisp,maybe they are helpful.
« Last Edit: July 01, 2010, 10:49:09 AM by highflybird »
I am a bilingualist,Chinese and Chinglish.

pkohut

  • Guest
Re: WScript and Autolisp
« Reply #4 on: July 01, 2010, 10:50:45 AM »
I've seen a couple samples of the 2 being used together but they were fairly basic.  Can redirection and output piping be done? How about retrieving the results sent to stdout?

em,What a good idea! I know few about WScript.  just watching. Can WScript put C++ and Lisp together?

Don't now much about WScript, but would think once the bridge is built between C++(ADS) and Autolisp it should not be a problem.  That's pretty much what I'm working on now. You notice that the openstream string is "cmd.exe" I think that could be changed to fire a mingw shell if one is install on the computer.  The first string is the application to run, the second the command line.

pkohut

  • Guest
Re: WScript and Autolisp
« Reply #5 on: July 01, 2010, 11:04:29 AM »
http://bbs.mjtd.com/dispbbs.asp?boardID=3&ID=62386&page=1
http://bbs.mjtd.com/dispbbs.asp?boardid=3&replyid=68044&id=62106&page=1&skin=0&Star=1

here are two articles about JScript and VBscript to Lisp,maybe they are helpful.

Interesting. That's different from the work I'm doing.

LE3

  • Guest
Re: WScript and Autolisp
« Reply #6 on: July 01, 2010, 11:07:44 AM »
I remember that Tony Tanzillo, did an example usage of WScript, might still be there in his site: caddzone.com

I've seen a couple samples of the 2 being used together but they were fairly basic.  Can redirection and output piping be done? How about retrieving the results sent to stdout?

TIA

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Re: WScript and Autolisp
« Reply #7 on: July 01, 2010, 11:16:11 AM »
wait a sec. I know this one.

...brb
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Re: WScript and Autolisp
« Reply #8 on: July 01, 2010, 11:23:16 AM »
Okay (thats what i thought but i wasnt sure), still no returns but i dont see how pipes couldn't be done.

I use mingw and hand spun stuff all the time via Autolisp like in the example link below; the std return would be cool as hell.

http://www.theswamp.org/index.php?topic=26914.msg336822#msg336822

TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

pkohut

  • Guest
Re: WScript and Autolisp
« Reply #9 on: July 01, 2010, 06:07:26 PM »
Okay (thats what i thought but i wasnt sure), still no returns but i dont see how pipes couldn't be done.

I use mingw and hand spun stuff all the time via Autolisp like in the example link below; the std return would be cool as hell.

http://www.theswamp.org/index.php?topic=26914.msg336822#msg336822



The std return part was easy to implement, and had that in the first version (http://www.theswamp.org/index.php?topic=33946.msg392742#msg392742), but it wasn't very flexible.

pkohut

  • Guest
Re: WScript and Autolisp
« Reply #10 on: July 01, 2010, 06:21:40 PM »
I remember that Tony Tanzillo, did an example usage of WScript, might still be there in his site: caddzone.com

I've seen a couple samples of the 2 being used together but they were fairly basic.  Can redirection and output piping be done? How about retrieving the results sent to stdout?

TIA

Thanks Luis.  If I go the WScript route then I may check it out.

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Re: WScript and Autolisp
« Reply #11 on: July 01, 2010, 06:24:28 PM »
You guys are way too cool! I cant wait till i can play along side with you guys. And BTW, im gonna check out that book as soon as im done with the one im reading now. Is it good?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

pkohut

  • Guest
Re: WScript and Autolisp
« Reply #12 on: July 01, 2010, 06:41:09 PM »
You guys are way too cool! I cant wait till i can play along side with you guys. And BTW, im gonna check out that book as soon as im done with the one im reading now. Is it good?

Very good book. So far up to chapter se7en and there has been very little code (reading it online so it's hard to skim). Up to this point I think even non programmers would enjoy the book as it has lots of history that effects the reason why things are done the way they are for Unix, Linux, BSD. And when it talks about pre OS X, Windows, VMS, etc., it doesn't bash them over the head, it gives fair treatment to the things they do right and wrong.

http://www.linuxtopia.org/online_books/programming_books/art_of_unix_programming/index.html
http://www.linuxtopia.org/online_books/index.html

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Re: WScript and Autolisp
« Reply #13 on: July 01, 2010, 06:47:05 PM »
I'm on it. Thanx.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

pkohut

  • Guest
Re: WScript and Autolisp
« Reply #14 on: July 02, 2010, 09:31:26 AM »
Second rewrite is now scrapped as it is complicated and hit a wall with the function "writeshelldata". It is/was based on code from http://support.microsoft.com/default.aspx?scid=kb;en-us;190351. Spent about 8 hours implementing, and 12 hours tweaking, rewriting, testing.

The third version is much simpler, but the writeshelldata function has the same issue. I thought a list of strings could be pumped through stdio to feed routines like sort.  Maybe I'm missing something about the way it suppose to work, will fire up Python later to test. Anyways, the third version is based on code from http://msdn.microsoft.com/en-us/library/ms682499. Spent about 5 hours on this version.

And the first version was based on _popen, but left a nasty looking cmd shell visible while running, and didn't have write capabilities either. Otherwise it was the simplest to implement, taking just a couple hours.

I've got to make a phone call in an hour or so which will dictate how the rest of the day is spent. With luck code will be release today.