Look at the "OS" module
n = OS_Shell(Command[, WindowStyle[, Mode]])
I think thats what your looking for.
Hi Folks,
I've probably missed the relevant entry in the documentation and examples.
If I have ProgramA.tbasic and ProgramB.tbasic, what instruction(s) should I use in ProgramA to fire ProgramB up?
The idea is that ProgramB will retain compulsory focus until it terminates, at which time the focus will return to ProgramA.
I have tried various things such as ProgramB(), ProgramB.tbasic() and CALL ProgramB(), but with no success. I have also tried including statements such as USES "ProgramB.tbasic".
Both programs exist in the same folder. I am running ProgramA from within thinAir, and ProgramB has not been compiled or obfuscated.
(I assume I'll be able to share variables such as the open TCP port variable (as evaluated by TCPFreeFIle = TCP_FREEFILE and TCPOpenError = TCP_Open(%PortNumber, "", TCPFreeFile, 1000)) by defining them as GLOBAL.)
Once again, all tips will be appreciated.
Regards,
Peter H. (gungadout)
Thought for the day (in a broad Australian accent):<br />First of all yer gungadin. Afterwards yer gungadout.
Look at the "OS" module
n = OS_Shell(Command[, WindowStyle[, Mode]])
I think thats what your looking for.
Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370
Hi Michael,
Thanks for the suggestion.
I've tried it, but it seems to pertain to invoking operating system commands only, unless I'm applying it incorrectly.
If I issue the command n = OS_Shell("cmd",,%OS_SHELL_SYNC), the Windows command window opens.
If I issue the command n = OS_Shell("ProgramB",,%OS_SHELL_SYNC) or n = OS_Shell("ProgramB.tbasic",,%OS_SHELL_SYNC), nothing happens.
In all three cases, the returned value in the variable n is zero.
So I'm still in the Twilight Zone, somewhat.
Is there something else I can try, or am I just not using the instruction correctly?
Regards,
Peter H.
Thought for the day (in a broad Australian accent):<br />First of all yer gungadin. Afterwards yer gungadout.
oops your right...save the 2 files in the same location and they should work.
Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370
Thanks, Michael.
Your examples worked well.
Two things I've noticed.
-------------------------------------
The first (which someone else may need to look at) is, that whatever value I place in the ShowCmd parameter, the calling program (Program1.tbasic) keeps on executing instead of waiting for the called program (Program2.tbasic) to terminate.
-------------------------------------
The second is, that my called program does not display or function at all unless there is a MSGBOX instruction before the first dialog instruction.
I guess I have to define some parameter within, or related to, the dialog instructions, but I'm not sure what.
-------------------------------------
Once again, all help will be appreciated.
Regards,
Peter H. (gungadout)
Thought for the day (in a broad Australian accent):<br />First of all yer gungadin. Afterwards yer gungadout.
Hi Folks,
I'm also finding that my GLOBAL TCPFreeFile variable has a value of 1 in my calling program, but 0 in my called program.
Is there an equivalent to the "named common" functionality in other Basic languages, which permits a variable evaluated in one program to have that value preserved in a program that it invokes, and a program that the invoked program then invokes, etc.?
E.g. (from a Basic I am used to):
Program 1 COMMON Variable1, Variable2, Variable3
Variable1 = "Red"
CALL Program2
PRINT Variable3 ("Blue" is printed)
Program2 COMMON Variable1,Variable3
PRINT Variable1 ("Red" is printed)
Variable3 = "Blue"
I know I can pass parameters in the OS_ShellExecute command (how does one retrieve them in the called program?), but that can be very awkward if many variables need to be passed. Also, can those parameters be passed bi-directionally, i.e. can the ByRef specification or an equivalent be used?)
Sorry for asking so many questions, but these things are not self-evident to me.
Regards,
Peter H.
Thought for the day (in a broad Australian accent):<br />First of all yer gungadin. Afterwards yer gungadout.
Hi Folks,
I've found out how to retrieve parameters passed by OS_ShellExecute. One uses OS_GetCommands and OS_GetCommand.
However, it seems that only literals can be passed.
If I run a program (Program1.tbasic) containing OS_ShellExecute("Open", APP_ScriptPath+"\Program2.tbasic", "AAA BBB", "", 1), the results I get in Program2 (parameters 2 & 3) are "AAA" and "BBB". Parameters 0 & 1 are as expected.
If I try to assign values to variables AAA and BBB in Program1 and use the command OS_ShellExecute("Open", APP_ScriptPath+"\Program2.tbasic", AAA BBB, "", 1), Program1 gets upset about the presence of BBB and falls over.
If I issue the command OS_ShellExecute("Open", APP_ScriptPath+"\Program2.tbasic", AAA, "", 1), where AAA is defined as LONG = 2476, Program2 receives the following values in parameters 0, 1, and 2, (using STR$() to display them) respectively: " 0", " 0", " 2476".
(I am going to use [ and ] as opening and closing quotes in my text below because the normal " character existed in the parameter displays.)
FYI, Issuing the command OS_ShellExecute("Open", APP_ScriptPath+"\Program2.tbasic", AAA, "", 1), where AAA is defined as LONG = 2476, Program2 receives the following values in parameters 0, 1, and 2, (without using STR$() to display them) respectively: [@1 "D:\thinBasic\00 Development\Program2.tbasic" ], [@1], ["D:\thinBasic\00 Development\Program2.tbasic"].
I know I could potentially convert everything to a concatenated string, pass that, then decode it in the receiving program, but one parameter I do need to pass is the FreeFile value, which I doubt can be transformed.
I guess the question remains:
(a) Is there a mechanism equivalent to the "named common" facilities in other Basic languages?
(b) Is there a way of passing multiple variable names of varying types in the OS_ShellExecute command or equivalent, especially bi-directionally, as is available in other Basic languages?
(c) If neither of the above is true, what else can I do, bearing in mind the FreeFile variable I need to pass?
Thanks,
Peter H. (gungadout)
Thought for the day (in a broad Australian accent):<br />First of all yer gungadin. Afterwards yer gungadout.
Hi Folks,
On _retesting_, the OS_ShellExecute("Open", APP_ScriptPath+"\Program2.tbasic", AAA, "", 1), where AAA is defined as LONG = 2476, Program2 __now consistently__ receives the following values in parameters 0, 1, and 2, (without using STR$() to display them) respectively: ["D:\thinBasic\00 Development\Program2.tbasic" 2476], ["D:\thinBasic\00 Development\Program2.tbasic"], [2476].
I've used [ and ] as my opening and closing quotes as explained in the previous post.
Using STR$() to display the results still results in " 0", " 0", " 2476".
Regards,
Peter H.
Thought for the day (in a broad Australian accent):<br />First of all yer gungadin. Afterwards yer gungadout.
Hi Peter,
I got a bit lost in your posts, but one thing has easy solution:
Sure it does not work, as 3rd parameter of OS_ShellExecute must be string.If I try to assign values to variables AAA and BBB in Program1 and use the command OS_ShellExecute("Open", APP_ScriptPath+"\Program2.tbasic", AAA BBB, "", 1), Program1 gets upset about the presence of BBB and falls over.
If you need to pass multiple values from numeric variables, you can try:
[code=thinbasic]
OS_ShellExecute("Open", APP_ScriptPath+"\Program2.tbasic", strFormat$("{1} {2}", AAA, BBB), "", 1)
[/code]
which will pass AAA as parameter1 and BBB as parameter2 in one string.
Windows are based on idea that one process cannot do any change to other process memory. That is why when you run two scripts with same names of variables, you will not see any interference. ( Simplified view on the problem of course )
To make programs communicate, it is recommended to use TCP commands, or memory files or processing WM_COPYDATA message.
From these, the TCP way seems the most typical to me.
I must admit I haven't seen any BASIC where variable interprocess sharing is possible, could you point me to some help files and examples of doing so? Maybe it will inspire some module... Still I consider it quite dangerous.
What happens when two scripts in mentioned languages attempt to write value to same variable at same time? Are there any syncing mechanisms?
I hope it helps,
Petr
Learn 3D graphics with ThinBASIC, learn TBGL!
Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB
For example of memory mapped files, please visit this thread:
http://community.thinbasic.com/index...12925#msg12925
It is very simple way to communicate. To avoid the critical situation of two files writing to same place, I recommend to setup:
- one file to read from program1 in program2
- one file to read from program2 in program1
- one file to write from program1 to program2
- one file to write from program2 to program1
As all files exist in memory, the interaction is fast. I think this mechanism could be solution for your script if you need to talk in realtime. If you need to just pass multiple parameters, simply use strFormat$ way.
Petr
Learn 3D graphics with ThinBASIC, learn TBGL!
Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB
Bookmarks