BBC BASIC for Windows
« Run one program from within another. »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:57pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Run one program from within another.  (Read 1166 times)
TheFamousCash
New Member
Image


member is offline

Avatar




PM


Posts: 16
xx Run one program from within another.
« Thread started on: Mar 20th, 2015, 5:57pm »

I know I am going to be shot down in flames but I cannot understand the simple command "*EXEC".

I wish to run a program then (from an instruction within that running program) run a different program. The original program no longer required.

I have experimented with *EXEC and *RUN (plus their OSCLI equivalents.)

The only "action" I achieved was a screen of corrupted output.

My understanding of the commands seems lacking.

Any advice on how I may accomplish this would be appreciated.
User IP Logged

rtr2
Guest
xx Re: Run one program from within another.
« Reply #1 on: Mar 20th, 2015, 6:05pm »

on Mar 20th, 2015, 5:57pm, TheFamousCash wrote:
I wish to run a program then (from an instruction within that running program) run a different program. The original program no longer required.

Sounds like CHAIN is what you are looking for. Rarely used in a 'modern' program, but does what you describe and should still work.

Remember that CHAIN, like INSTALL and CALL, requires the program to be saved in .BBC (tokenised) format; that's the default so it probably is anyway, but it's as well to be aware of the restriction.

Richard.
User IP Logged

TheFamousCash
New Member
Image


member is offline

Avatar




PM


Posts: 16
xx Re: Run one program from within another.
« Reply #2 on: Mar 20th, 2015, 6:15pm »

Thanks, Richard but |I should have stated it is a compiled program.

I used to use chain many years ago quite successfully but need the equivalent for the exe program.
User IP Logged

rtr2
Guest
xx Re: Run one program from within another.
« Reply #3 on: Mar 20th, 2015, 7:40pm »

on Mar 20th, 2015, 6:15pm, TheFamousCash wrote:
Thanks, Richard but |I should have stated it is a compiled program.

In that case you've got yourself rather muddled. There's no way you can run an EXE in such a way that it automatically replaces or discards the current program. An EXE will necessarily be run in a separate process, and will return control to the program which called it (either immediately or on completion, as discussed recently in another thread).

The most you could do is to execute a QUIT statement in the calling program once the EXE has been launched, so that the original process is terminated. Hopefully that will at least have the required behaviour as far as the user is concerned, even if what's happening 'under the hood' is rather different from what you originally envisaged.

Richard.

User IP Logged

TheFamousCash
New Member
Image


member is offline

Avatar




PM


Posts: 16
xx Re: Run one program from within another.
« Reply #4 on: Mar 20th, 2015, 8:02pm »

Thanks again, Richard.

If I follow correctly, you are saying an *EXEC command within a complied (.exe) program can run another similar program and then return to that point in the original program.

I experimented by compiling a program which simply printed a message to the screen and tried to run it by the above method without success. (Both *EXEC and OSCLI)

It just resulted in some flashing screen and nothing else.

If I am misunderstanding something simple, please accept my apologies and I will just carry on experimenting.

Bob.

User IP Logged

rtr2
Guest
xx Re: Run one program from within another.
« Reply #5 on: Mar 20th, 2015, 9:31pm »

on Mar 20th, 2015, 8:02pm, TheFamousCash wrote:
If I follow correctly, you are saying an *EXEC command within a complied (.exe) program can run another similar program

You don't mean *EXEC (that does what it did on the BBC Micro). *RUN is probably the most straightforward method when it does what you want, but you mentioned that you had already tried it (and its OSCLI equivalent) and that it had failed for some reason:

http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin8.html#starun

If you can't use *RUN, alternative methods to consider are SYS "ShellExecute", SYS "WinExec" and SYS "CreateProcess". They all do similar things and the choice of which to use will depend on what degree of control you need over the window show state, whether it waits for the program to complete and so on. As always if you choose to use a Windows API call make sure you understand the MSDN description and be careful to pass the correct parameters.

Richard.
User IP Logged

TheFamousCash
New Member
Image


member is offline

Avatar




PM


Posts: 16
xx Re: Run one program from within another.
« Reply #6 on: Mar 21st, 2015, 5:47pm »

I spent some time experimenting before acknowledging your kind response because I felt certain there must have been something wrong with my coding.

I wrote an elementary program to check all permutations and discovered *RUN is (of course) the solution. The reason, (at least, I am pretty sure) concerns the fact my original program used full screen. The secondary program which was *RUN from the original was, in fact, running in the background although no input was accepted and was not visible.

One problem yet to solve. . . I understand a program cannot delete itself but the installation program (on disc) copies files, including the user's main program, to the computer then deletes them from the disc. (No problem.) It then goes on to use *RUN to run the newly installed users main program from the computer. (Now successful with the above problem now solved.)

That main program (before proceeding to operate properly) now attempts to delete the installation program from the disc which is still waiting for the user's program to terminate. It does not do so and there is no error message. I am assuming it is because it is not possible to delete from disc because it is running.

When the program is exited and the newly installed shortcut is clicked to run the users main program, it DOES delete the installation program from disc, if it is still in drive.

Thank you once again for your patience and invaluable help.

Regards,

Bob.

User IP Logged

rtr2
Guest
xx Re: Run one program from within another.
« Reply #7 on: Mar 21st, 2015, 6:20pm »

on Mar 21st, 2015, 5:47pm, TheFamousCash wrote:
The reason, (at least, I am pretty sure) concerns the fact my original program used full screen...

IMO you need to have a very good reason for running full screen. This laptop display is 1920 x 1080 pixels, which is an awful lot of real estate to be filled with just one program, however awesome its designer thinks it is! So if, as a result, your calling program obscured the called program I have no sympathy whatever. tongue

Anyway, if the calling program is no longer needed, why do you leave it running? As I said before, there is no reason why it shouldn't do a QUIT as soon as the external process has been successfully spawned.

Richard.
User IP Logged

TheFamousCash
New Member
Image


member is offline

Avatar




PM


Posts: 16
xx Re: Run one program from within another.
« Reply #8 on: Mar 21st, 2015, 7:11pm »

I am aware of your dislike for programs using full screen and I agree in principle. There is no point in justifying why I used it in this particular program, it just happens it caused the problem.

Unless I am mistaken, if I *RUN a program from within another, I can't exit the program before executing the command.

The next command after the *RUN command is *QUIT.

If I *QUIT, I can't then *RUN as the program has terminated.

Bob.
User IP Logged

rtr2
Guest
xx Re: Run one program from within another.
« Reply #9 on: Mar 21st, 2015, 9:16pm »

on Mar 21st, 2015, 7:11pm, TheFamousCash wrote:
The next command after the *RUN command is *QUIT. If I *QUIT, I can't then *RUN as the program has terminated.

I don't follow. I was suggesting that you *RUN the external program without waiting for it to complete (semicolon terminator), then immediately execute a QUIT statement in the calling program. That way there's only a very short 'overlap' during which both programs are running simultaneously. That's the closest you can get to a CHAIN-like behaviour with EXEs, which I thought was what you wanted. Maybe I misunderstood.

I should perhaps say, in all fairness, that what you are trying to achieve would be significantly easier in Liberty BASIC!

Richard.
« Last Edit: Mar 21st, 2015, 9:18pm by rtr2 » User IP Logged

TheFamousCash
New Member
Image


member is offline

Avatar




PM


Posts: 16
xx Re: Run one program from within another.
« Reply #10 on: Mar 23rd, 2015, 3:12pm »

Just for completeness.

I have successfully achieved the goal.

Customer's disc contains an "exe" "INSTALL" program and a folder containing his main "exe" program and associated files.

Activating the "INSTALL" program loads the contents of the folder (main program and files) to customer's computer and deletes all files (including the "INSTALL" program) on the disc. The main program is then *RUN.

Many thanks, once again, for your invaluable help and patience.

Regards,

Bob.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls