OS_ShellExecute a sequence of programs (a daisy-chain)
Hi all,
Can anyone help with this problem?
I would like to run an initial program (call it Prog1) which, when it has finished its purpose, runs another program (call it Prog2) and Prog1 stops, whilst Prog2 continues.
Then, when Prog2 has finished its purpose, it runs another program (call it Prog3) and Prog2 stops, whilst Prog3 continues, etc, etc.
I have written three simple test programs to see how this might work, but no matter what I do, I can only get one program to execute another. The next execution attempted (by the second program) fails, without any error.
e.g. Prog1 will run Prog2, but Prog2 won't run Prog3. Also Prog2 will run Prog3, so there appears to be nothing wrong with the code in Prog2.
It's a complete puzzle. Is there a limit of only one operation in the OS_ShellExecute function?
I am running Win7 64-bit.
My code for Prog1 is shown below and is virtually identical in Prog2, etc, except that the titles of the programs being executed are changed to the appropriate ones:
Code:
' Test OS_ShellExecute
' Prog 1
Uses "OS", "console"
Dim pID As Long
Cls
PrintL "PROGRAM 1."
PrintL
PrintL "Now about to run Program 2....."
pID = OS_ShellExecute("open","OS_Shell_prog2.tbasic","","",1)
PrintL "pID=",pID
PrintL
If pID>0 Then
PrintL "pID was greater than zero, so Prog 2 should run."
End If
WaitKey
regards
JohnP
OS_ShellExecute a sequence of programs (a daisy-chain)
Hi John, Eros,
Thank you both for your very prompt and helpful replies.
@John:
I have had an eye on ScriptBasic for some time and will keep up my interest, thanks.
@Eros:
Your explanation has hit the nail on the head.
I have obviously misinterpreted the purpose of the OS_ShellExecute command and if the thinBasic Help file is extended to contain your clarification, it will help others from falling into the trap that I did.
I have run your suggested code and it does exactly what I wanted.
At a stroke, you have solved a problem I have had for months!
It allows me to split a long, complex program up into 'modules' (each of which deal with particular program operations and which I can use for other related programming tasks) which are each sequentially executed. That helps me to concentrate on programming specific functions within each 'module' and, then, when I encounter an error, it helps me to locate and deal with that specific error more quickly.
Thank again,
regards
John
OS_ShellExecute a sequence of programs (a daisy-chain)
Quote:
Originally Posted by
ErosOlmi
Next time, do not wait and ask ;)
We are here to help. Maybe we cannot reply in one second, maybe we have a solution for the next day or so but we will try our best to explain and find a way.
Also requests like yours let us know that something is not correct in thinBasic and/or thinBasic documentation letting us improve the material we produce.
Ciao and thanks
Eros
Eros,
I try not to waste your valuable time. So I try to solve a problem first, before asking.
But OK, I'll still do that, but will ask for help sooner in future.
Right! Here is the next question then! :D
If the programs being called sequentially have been 'bundled' (NextScript_Name = 'OS_Shell_Prog2.exe' rather than 'OS_Shell_Prog2.tbasic'), how do you then refer to them in the code below?
NextScript_pID = OS_Shell(thinBasic & " " & $DQ & NextScript_Name & $DQ, %OS_WNDSTYLE_NORMAL, %OS_SHELL_ASYNC)
I guessed that one omits the 'thinbasic & ""' part, but that didn't work.
regards
JohnP
OS_ShellExecute a sequence of programs (a daisy-chain)
Quote:
Originally Posted by
ErosOlmi
Ok, here thinBasic has a problem and at the moment I do not know how to solve......... So, I'm sorry but I do not a solution right now using bundled exe.
Last chance is to use obfuscated scripts, their execution is like executing a normal script (so previous examples should work) and change script extension to .tBasicx.
The problem here is that you must have thinBasic installed in your target machine.
Eros,
I am most grateful for your comprehensive reply.
It really helps to know when one has reached the current limits, and so I won't try to do the impossible!
I will stick to using plain normal script, for simplicity, with thinBasic installed on the target machine. That's fine, thanks.
regards
JohnP