|
Post by get1960 on Dec 22, 2018 17:01:04 GMT -5
Hello.
Is it possible to invoke one program in another? For example: I have two programs(A and B). When I execute program A I want to execute program B. I know I can combine the two programs into one, however, I would like to know if it is possible. If so, how.
Thanks, George
|
|
|
Post by alincon on Dec 22, 2018 19:55:55 GMT -5
You can make a tokenized or executable LB program easily and call them from other LB programs. But, if I am not mistaken, the calling program will not wait for the called program to finish, it will keep running.
r.m.
|
|
|
Post by tsh73 on Dec 23, 2018 7:58:11 GMT -5
You'd rather check this - but - quote from old JB Wiki
Synchronous vs asynchronous As was stated, "The JB program will continue to run". More precisely, then running EXE program, (or BAT file), JB continue to line following RUN statement instantly, without waiting for RUN'd program to finish. (actually JB has no means to tell if it finished). This is, EXE program runs asynchronously. If you run another JB program via runtime run "jbrun101.exe myProg.tkn" , your code will continue instantly along with running myProg.tkn. BUT if you run TKN without mentioning runtime engine run "myProg.tkn" , your code will *HALT* and *WAIT* till code in myProg.tkn finishes. This is, TKN program runs synchronously. Probably this way, it uses same engine as your main (caller) program. this is not documented - experiment first.
Checking under Windows XP - it does work for me child.bas
print "*CHILD PROGRAM*" print "Program is called" print time$() input "Press Enter to continue";a$ print "Program ends ";time$() end
compiled to child.tkn
parent.bas
print "*PARENT PROGRAM*" input "enter 1 to run and wait, overwise run without wait "; ans$ print "Program is called" print time$() if trim$(ans$)="1" then run "child.tkn" else run "run451.exe child.tkn" end if print "Program returns ";time$() end
So save child.bas, create child.TKN, make parent.bas and run it. It either returns instantly or waits for child program to end.
|
|
|
Post by mknarr on Dec 23, 2018 11:00:15 GMT -5
I'll add to tsh, in a commercial program I have, I run several programs from one program and I'll give several examples. The first three runs something and continues to either an end or goes to a wait.
In this code, the first program runs the second and ends
run "second.exe somestring$" end
The somestring$ is actually a commandline string passing something to the second program.
this code runs Notepad and displays a text file.
run "write.exe "+chr$(34) + File$ + chr$(34), SHOWMAXIMIZED wait
This code runs explorer and displays a pdf file.
run "explorer ";DefaultDir$+"\some.pdf" wait
The following code runs another program and waits for it to finish before continuing.
....... call RunWait filename$,"", DefaultDir$ wait ........
sub RunWait File$, a$, dir$ SEE.MASK.NOCLOSEPROCESS = hexdec("40") SEE.MASK.FLAG.DDEWAIT = hexdec("100") struct ExecInfo, _ Size as long, _ fMask as long, _ hwnd as long, _ Verb$ as ptr, _ File$ as ptr, _ Parameters$ as ptr, _ Directory$ as ptr, _ Show as long, _ InstApp as long, _ IDList as long, _ Class$ as ptr, _ keyClass as long, _ HotKey as long, _ Icon as long, _ Process as long ExecInfo.fMask.struct = SEE.MASK.NOCLOSEPROCESS or SEE.MASK.FLAG.DDEWAIT ExecInfo.File$.struct = File$ + chr$(0) ExecInfo.Parameters$.struct = a$ + chr$(0) ExecInfo.Directory$.struct = dir$ + chr$(0) ExecInfo.Show.struct = _SW_SHOWNORMAL ExecInfo.Size.struct = len(ExecInfo.struct) calldll #shell32, "ShellExecuteExA", _ ExecInfo as struct, _ result as long if result <> 0 then Handle = ExecInfo.Process.struct Milliseconds = _INFINITE calldll #kernel32, "WaitForSingleObject", _ Handle as long, _ Milliseconds as long, _ result as long end if end sub
|
|