View Full Version : OS_Shell - question/issue
ReneMiner
28-08-2015, 15:26
I have one bundled .exe-file that i start from another Script using OS_Shell.
Help tells, TBMain-Result (of my .exe-file) would get passed somewhere,
i assumed it would be the OS_Shell-return-value then - but it's in fact the processID that's returned by OS_Shell.
So where to find return-value of TBMain() /App_ReturnCode after the process has finished?
- can a bundled .exe-file return something at all besides writing the result into a file?
ErosOlmi
31-08-2015, 11:01
Ciao Renč,
I need to check the whole process and see if I missed some point where I didn't returned the TBMain return code or APP_SetReturnCode (http://www.thinbasic.com/public/products/thinBasic/help/html/app_setreturncode.htm) in case no TBMain.
Maybe the last Bundle version introduced this problem.
I will let you know.
Ciao
Eros
ErosOlmi
15-09-2015, 16:07
Ciao Renč,
I've found the problem and fixed.
By the end of the week I will give you a 1.9.16 version to test.
Ciao
Eros
ReneMiner
16-09-2015, 09:39
Which would be the Keyword to retrieve an app-returncode after OS_Shell was called and the process has finished?
ErosOlmi
16-09-2015, 11:29
Well, I've fixed the chain of the return code to the operating system.
In next version, if you will execute a script (both from source or from bundled executable) you will be able to determine a ERRORLEVEL from a .CMD command file like:
call YourScript.exe
if errorlevel 1 goto handleerror1orhigher
if errorlevel 0 echo succuess...
Now I need to understand how to get that return code when SHELLed from inside another application.
I'm not aware of any way of doing that at the moment.
ErosOlmi
16-09-2015, 12:21
I think I've found a way.
When OS_Shell is executed in async mode, it will return the process id.
When OS_Shell is executed in sync mode, it will return the executed application exit code.
I need to change the OS module and make some tests but quite confident I will get it.
I will let you know.
Eros
ReneMiner
16-09-2015, 16:56
sounds good & reasonable.
:)
is there a way for async-mode to transfer any information back to the application that called
OS_Shell("otherApplication.exe", %OS_WNDSTYLE_NORMAL, %OS_SHELL_ASYNC)
while both are still running?
ErosOlmi
16-09-2015, 19:43
Well, in async way you can always use the process ID returned by OS_Shell to monitor the process.
There are a lot of Windows API to use for this purpose.
Instead, if you mean to let the two process talk each other while running ... in this case there are some ways:
One could be using TCP/UDP on the local server (local machine). Not complex to develop. Some example in \thinBasic\SampleScripts\TCPUDP\
Check UDP_Notify_Client.tbasic and UDP_Notify_Server.tbasic
Execute the server and click on "I'm the server"
Than execute the client and click on "Find server"
If each other are able to talk, just move the client window and you will see ...
You can run up to 10 client able to each exchange data with the server.
Protocol used is very simple, you can invent your own way
another way could be the so called "Interprocess Communications".
There are many ways in which this can be achieve, some quite complex, some more easy.
Maybe one day we will develop something in thinBasic in order to let thinBasic scripts to talk each other while running.
The complex thing is that there are many different ways/data/structures one can invent and making a "general" way is not so easy.
Ciao
Eros
ReneMiner
16-09-2015, 20:18
is it possible to share memory-areas between different apps?
Maybe first script allocates some heap and sends the heap-pointer as a command-parameter on OS_Shell,
now the second app could set values inside that heap? Or would this lead to some unavoideable access-violation-error?
Or could it work somehow similar to Oxygen to set a "shared function-pointer" via Declare Function ... At ?
ErosOlmi
16-09-2015, 22:18
Unfortunately (or fortunately) memory is by process.
In general Windows operating system reserve a virtual memory space of 2GB per every process running.
That virtual memory is by process.
In old Windows version (mainly 16 bit up to windows 9x) memory was shared between all process and that was one of the reasons why very often a crash in a process was crashing the entire operating system causing the computer to hang. In 32 bit Windows (from W2K) memory cannot be share between process without passing though the OS using some of the techniques I mentioned before.
ErosOlmi
16-09-2015, 22:27
A way is to use CreateFileMapping API to create/open a memory mapped file
https://msdn.microsoft.com/en-us/library/windows/desktop/aa366537(v=vs.85).aspx
Here a PowerBasic example on how to create/share a piece of memory between process with memory mapped files:
https://www.powerbasic.com/support/pbforums/showthread.php?t=16140
Maybe we can get inspiration for a future thinBasic module dediated to this aspect.
ReneMiner
16-09-2015, 22:38
so there's only "the unsafe way" of using the clipboard... or networking :confused::confused::confused:
ErosOlmi
16-09-2015, 22:44
The contrary: there are many ways everyone can develop.
If I will develop something native into thinBasic I will need to find a as much as possible general way able to cover many different situations.
Actually my preferred possible way is memory mapped files.
More info on MMF
https://msdn.microsoft.com/en-US/library/dd997372(v=vs.100).aspx