English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. Blitz Basic

 
 
Thread Tools
Old 31 July 2019, 16:18   #1
themamboman
Registered User
 
Join Date: Dec 2012
Location: Atlanta, USA
Posts: 151
AmiBlitz calling external programs?

Sorry if this has been asked before, I couldn't find an answer right off.

Does AmiBlitz/BlitzBasic2 have a method to call an external program, or something in the C: directory, along with passing parameters and receiving the output back for parsing?

It would make some of my projects much easier than having to replicate the functionality of those small programs inside AmiBlitz.

Thanks!
themamboman is offline  
Old 31 July 2019, 17:39   #2
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 4,450
Yep - well, Blitz doesn't itself, but you can use the OS Execute() call pretty easily:

Code:
succ.l = Execute_ ("List Files: >T:templist", 0, 0)
The result stored in succ.l is just whether the command could be run, and will still return success even if the command fails (e.g. if the Files: volume didn't exist). The two zero parameters are file handles for input and output streams, and you can just leave them at 0 for most purposes.

If you want to control the parameters, you should build up the string you need first:

Code:
myDir$ = "SYS:Tools"
myCommand$ = "List " + myDir$ + " >T:templist"
succ.l = Execute_ (myCommand$, 0, 0)
There's no (easy) way to directly receive the results. You're better off just running the command to a temp file like I did, then opening the temp file using OpenFile() and reading in the results using FileInput and Edit$().

Have a look at some of the extra command libraries though, there are some that include lots of DOS functions for copying files, making directories, stepping through directory listings etc. that might be enough for you, depending on what exactly you're trying to do. For example, the ElmoreDOSLib is part of the standard Blitz CD installation, and the enhanced floppy installation. It's also part of AmiBlitz. If AmiBlitz 3 is an option however, there are also the dos.include and file.include includes that contain even more useful file handling functions.

Last edited by Daedalus; 01 August 2019 at 16:35. Reason: Fixed code error
Daedalus is offline  
Old 01 August 2019, 16:20   #3
themamboman
Registered User
 
Join Date: Dec 2012
Location: Atlanta, USA
Posts: 151
Thanks for that!

I'm guessing that the call to execute will pend on the called application ending and sending back the response?

As just an example, if I have something calls, say, ffmpeg, and it takes a while to get the end result, then my code will just stop? Guess it was too much to hope that Amiblitz / Blitz Basic could get a stream of output of the called app's standard output to examine?

That brings up another question, if calling something locks up until the response is received, is it possible to spawn off another thread? I know I'm getting way off base here, just curious what is possible and reasonable to expect.

thanks again!
themamboman is offline  
Old 01 August 2019, 16:40   #4
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 4,450
Yeah, if you want the stream of output, that gets a little trickier alright. Amiblitz has wrapper functions for launching external tasks asynchronously so your code will run in parallel, but Blitz 2.1 doesn't. You can, however, simply put the Run command at the start of your command string:

Code:
myDir$ = "SYS:Tools"
myCommand$ = "Run >NIL: List " + myDir$ + " >T:templist"
succ.l = Execute_ (myCommand$, 0, 0)
Getting a stream of output is tricky, primarily because the output file will be open and continuously written to. You could try checking the filesize of the temporary file and reading it in every time it changes. I'm not sure if reading the file until EOF() and then repeatedly checking for EOF() again works to see if additional content has been added, but it's also worth trying.

The >NIL: after the Run should stop you getting the new shell process notifications each time it runs.


Oops, just noticed the Execute function should get the myCommand$ string, not myDir$...
Daedalus is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Amiblitz 3 Retrofan Amiga scene 2 15 December 2016 23:55
AmiBlitz 3 AF2013 Coders. Blitz Basic 13 26 September 2013 01:27
AmiBlitz 3 slk486 support.Apps 2 16 May 2010 22:26
Amiga E: Running external programs lennonlives support.Apps 6 09 October 2008 19:46
New Amiblitz (2.42) released Paul News 0 06 September 2004 21:01

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 23:27.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Page generated in 0.06136 seconds with 13 queries