Script A wants to know what Script B is doing

Started by stevengraff, March 21, 2014, 05:35:02 AM

Previous topic - Next topic

stevengraff

From time to time I seem to recall seeing snippets of discussion on the topic of inter-script communication and, I suppose, that's where I'm edging into with this question. I couldn't find said discussions, so, sorry if this is a repeat-ish question.

1. I start Script A.
2. I start Script B, and I want B to do a task based, in part, on what Script A is currently doing. ("Hey, A, which record in the db are you presently processing? Oh, I see by your "published" attribute 'curRecord' that you are now working on record 'xyzzy' ". ) So I want B to be able to query A to get its status.

A very "blunt instrument" approach is to have A update its dialog's Title with some kind of status code... and B could easily read it. Or, A could write a temp file to disk and B could read it.

But there must be better, tighter, more direct, more foolproof ways, right?

Thanks,
SG


JTaylor

Take a look at Named Pipes as another option.

Jim

snowsnowsnow

Or shared memory - which I always found a lot easier to work with than Named Pipes.

Note: Names pipes, on any OS, starting with Unix (where they came from and where I first used them), have always seemed unnecessarily hard to use.  I've never really had a fully actualized use of them (on either OS).

Search the Tech DB for "shared memory".

Or use the attached fileââ,¬Â¦

stevengraff

So, using shared memory, in script A I use:

newmem = OpenSharedMemory('x')
status = WriteSharedMemory(newmem,"Hello")
read = ReadSharedMemory(newmem)
done = CloseSharedMemory(newmem)

which writes "Hello" into newmem, then, in script B I use:

newmem = OpenSharedMemory('x')
read = ReadSharedMemory(newmem)
done = CloseSharedMemory(newmem)

in which I can see that newmem = "Hello"

Have I got that right?

Deana

Deana F.
Technical Support
Wilson WindowWare Inc.

JTaylor

Thanks for the question...the responses may solve a problem for me.

Jim

snowsnowsnow

Quote from: stevengraff on March 21, 2014, 07:25:06 AM
So, using shared memory, in script A I use:

newmem = OpenSharedMemory('x')
status = WriteSharedMemory(newmem,"Hello")
read = ReadSharedMemory(newmem)
done = CloseSharedMemory(newmem)

which writes "Hello" into newmem, then, in script B I use:

newmem = OpenSharedMemory('x')
read = ReadSharedMemory(newmem)
done = CloseSharedMemory(newmem)

in which I can see that newmem = "Hello"

Have I got that right?

Pretty much, except that you don't want to close it, because closing it (specifically, the last close) causes the shared memory to disappear from the system.

The model should be something like:

; At top of Script A, create the shared memory segment
newmem = Openââ,¬Â¦

; In main loop
; use newmem


Similarly in script Bââ,¬Â¦

The trick is that the "Open" function (in the WBT code) is dual purpose, without any possibility of disambiguation, covering both "creating" the shared mem and also the opening up of an existing shared mem.

So, you need to make sure to get the timing right - A has to create it first, before B tries to open it.

stevengraff

Actually, I'm not seeing anything so far that destroys the data or the field.

On A I'm using:

newmem = OpenSharedMemory('x')
status = WriteSharedMemory(newmem,"Hello")
done = CloseSharedMemory(newmem)

and on B I'm using:

newmem = OpenSharedMemory('x')
read = ReadSharedMemory(newmem)
done = CloseSharedMemory(newmem)

I can run through B all day long, and "Hello" still comes back, every time. How do I kill it?