(link'ing and (!'ing Example

Q&A's, tips, howto's
Locked
CaveGuy
Posts: 112
Joined: Sun Oct 13, 2002 3:00 pm
Location: Columbus Ohio
Contact:

(link'ing and (!'ing Example

Post by CaveGuy »

The following example should provide some clue to
building and (!'ing newLISP executables.

We will use the link.lsp example from the source distribution set to link DoTest-p and SoTest-c into standalone EXEs.

DoTest-p is a parent task that (!s' DoTest-c.exe as a child task.
DoTest-c (loads' DoTest-0.dat which (sets' a return list to pass back to its parent, DoTest-p using an intermediate file DoTest-1.Dat.
Upon return to DoTest-p's control DoTest-1.dat is (loaded.

(link "newlisp.exe" "DoTest-p.exe" "DoTest-p.lsp")
(link "newlisp.exe" "DoTest-c.exe" "DoTest-c.lsp")

;; dolist-0.dat
(set 'done '(X 1 Y 2 Z 3))

;; dotest-p.lsp
(define (run)
(time (if (= (! "DoTest-c.exe") 2) (load "DoTest-1.dat")))
(print return))
(run)
;; eof

;; Dotest-c.lsp
(load "DoTest-0.dat") ; get and set a value for 'done to return.
(set 'fh (open "DoTest-1.dat" "write"))
(write-line (append "(set 'return '" (string done) ")") fh)
(close fh)
(exit 2)
;; eof

;; link.lsp example included in the source distribution set.
;;
(define (link orgExe newExeName lispSourceName)
(set 'size (first (file-info orgExe)))

;; copy newLISP.exe to the newExeName
(copy-file orgExe newExeName)

;; get the binary representation of size
(set 'buff (pack "ld" size))

;; open the new exe for update
(set 'handle (open newExeName "u"))
(search handle "@@@@@@@@")

;; this field gets read by the newLISP startup
(write-buffer handle 'buff 4)
(set 'buff (trim (read-file lispSourceName)))
(set 'keylen (pack "ld" (length buff)))
(write-buffer handle 'keylen 4)

;; append lisp source at the end
(seek handle size)
(set 'buff (encrypt buff (string (length buff))))
(write-buffer handle 'buff (length buff))
(close handle))
;; eof


I have a vague memory of seeing somewhere mention of how to eliminate the flashing black window to nowhere. I can not seem to find it again :(

At one point in my testing I built a feedback loop that flash a window every 300ms till I got it stopped :)

This example and the one that this will evolve into in real life need to pass the file name of the return data to avoid collision with other processes.

Wish List Item:
(get-tmp-filename) returns a unique temp filename using the system call.
Bob the Caveguy aka Lord High Fixer.

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

To avoid the flicker:

From newlisp-tk help:

In the file newlisp-tk.config include the following line:

set Ide(initCommand) "wm withdraw ."
Hans-Peter

CaveGuy
Posts: 112
Joined: Sun Oct 13, 2002 3:00 pm
Location: Columbus Ohio
Contact:

Post by CaveGuy »

That is a problem, I am linking stand-alone EXE's using newLISP.exe and newLISP-TK is not running. These EXEs are created by the hundreds and stored in USER space with no access to newLISP. A command line parameter would be just OK. A first line in the source that was loaded into the EXE would be much better.
That should be the same as putting it in init.lsp.

These inteligent storage orbs, need to save their context back into themselves and go back to sleep after they have been accessed. Thanks for the info, I had not thought to look back in the TK doc as I was not using any TK for this project. I understand it is hard to keep track without a score card :)
Bob the Caveguy aka Lord High Fixer.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

I am not sure that the TK anti-flicker mechanism will help you. If I understand you well, you are running a newlisp.exe (linked with source) and want to get rid of the popping up black dos box? Your linked "DoTest.exe" does some processing and reads/writes files, but doesn't do any console I/O and shouldn't need the DOS console window?

I have tried the following: I created a little batch file "batch.bat" , which contains:

---- cut here -----
dir > listing.txt
---- cut here -----

So when I doubleclick on "batch.bat" the black DOS box pops up quickly, but it also creates a file "listings.txt" which contains a directory listing.

Now I did the following: I created a link on the desktop and in the properties window (right click the file) I changed in the "shortcut" tab the setting of the "run:" option from "normal window" to "minimized".

Now I only see a little icon appearing and disappearing on the status bar.

Does this help?

CaveGuy
Posts: 112
Joined: Sun Oct 13, 2002 3:00 pm
Location: Columbus Ohio
Contact:

Post by CaveGuy »

The flashing problem gets real bad running as a background task on the server. While testing a live feed, fireing off 100+ tasks per minute, the server'sconsole became unuseable.

Back to the drawing board, I need to re-think this one.
In full production I expect to have hundreds of tasks rotating every few seconds.

NewLISP CGI's dont flash, like some other exe's do. But I expect that is due to the way Website spawns the process. I will have to go back and take a look at the spawn options again.
Bob the Caveguy aka Lord High Fixer.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

Perhaps you should run a Cygwin compiled version. You would still be on Windows, but maybe without these kinds of problems.

Also, at this moment how to you invoke the child process? are you using the '!' operator or are you using 'exec' (formerly read/write-process). In both compilers '!' is based on a C-library call system() and 'exec' is built on popen() in both compilers. Perhaps consutling the docs of both, you can find out what the underlying Win32 calls are.

I mean when Cygwin can do it, it must be possible, because Cygwin is just a layer on top of the Win32 API.

Just some thoughts ...

Lutz

ps: where are the Win32 experts on this forum ;)

Locked