English Amiga Board


Go Back   English Amiga Board > Coders > Coders. System

 
 
Thread Tools
Old 11 August 2018, 19:14   #1
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 45
Posts: 2,997
run a program from within another

Hi,

The problem here is to simply launch some program, wait for it to return (or not), and (eventually) continue with the original code. Say, calling some external program like a routine would be.

I could run a program with SystemTagList() or Execute() but I can not detect if the target program exists or not : if it does not, this stupidly writes some "command not found" message to the console...
In addition it seems SystemTagList() is unable to run a program with PROGDIR: in the path for the executable...
It also seems there's no way to grab the return code of the command.

So did I miss something important or is dos.library real stupid ?

Note : used language is asm. But it shouldn't matter.
meynaf is offline  
AdSense AdSense  
Old 11 August 2018, 19:26   #2
SavageMonkey
Registered User

 
Join Date: Jan 2016
Location: Cheshire, UK
Posts: 9
Could you use execute() and redirect the command's output to NIL: ..?
SavageMonkey is offline  
Old 11 August 2018, 19:30   #3
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 45
Posts: 2,997
I do *not* want to redirect the command's output to NIL: because the program I run may well output something useful.
Besides, this would just fail silently if it's not found.
meynaf is offline  
Old 11 August 2018, 19:37   #4
SavageMonkey
Registered User

 
Join Date: Jan 2016
Location: Cheshire, UK
Posts: 9
Why can't you detect the program's existence first?
SavageMonkey is offline  
Old 11 August 2018, 19:41   #5
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 45
Posts: 2,997
The fact a file exists doesn't make it a valid executable.
meynaf is offline  
Old 11 August 2018, 19:44   #6
ross
Omnia fert aetas

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 48
Posts: 949
LoadSeg?
ross is offline  
Old 11 August 2018, 19:45   #7
SavageMonkey
Registered User

 
Join Date: Jan 2016
Location: Cheshire, UK
Posts: 9
I know, you said you couldn't tell if the target program exists or not, I wondered why.
SavageMonkey is offline  
Old 11 August 2018, 19:54   #8
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 45
Posts: 2,997
Quote:
Originally Posted by ross View Post
LoadSeg?
That will just load the program in memory, not create a new process, allocate stack, give args, etc.


Quote:
Originally Posted by SavageMonkey View Post
I know, you said you couldn't tell if the target program exists or not, I wondered why.
Well the program may exist but still fail in a number of ways... It's general failure i wish to catch.
meynaf is offline  
Old 11 August 2018, 19:56   #9
ross
Omnia fert aetas

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 48
Posts: 949
Quote:
Originally Posted by meynaf View Post
That will just load the program in memory, not create a new process, allocate stack, give args, etc.
You can manually do it
I realize that it is a little inconvenient..
ross is offline  
Old 11 August 2018, 20:01   #10
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 45
Posts: 2,997
Quote:
Originally Posted by ross View Post
I realize that it is a little inconvenient..
Apparently, yes. I just wanted some "cheap" way. Seems Atari ST has better PEXEC function
meynaf is offline  
Old 11 August 2018, 20:07   #11
SavageMonkey
Registered User

 
Join Date: Jan 2016
Location: Cheshire, UK
Posts: 9
It's a shame that Execute() doesn't return the command's return code.

I'm not sure of your use case but wonder if you could write a script that runs your command and checks its return code and execute the script instead, though I appreciate that's a bit clunky.
SavageMonkey is offline  
Old 11 August 2018, 20:16   #12
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 45
Posts: 2,997
My use case is to write a wrapper function and then reuse it in every program that will need to call another. Therefore it must be clean of "clunky" things

Now wondering if i can do that (or not) with LoadSeg and CreateNewProc/RunCommand.
Of course i'd like to have both synchronous and asynchronous modes
meynaf is offline  
Old 11 August 2018, 20:20   #13
alkis
Registered User

 
Join Date: Dec 2010
Location: Athens/Greece
Age: 47
Posts: 428
Autodocs on execute say the result is bool on if it found and executed the prorgam or not.

http://amigadev.elowar.com/read/ADCD.../node015E.html

That does not apply?
alkis is offline  
Old 11 August 2018, 20:22   #14
SavageMonkey
Registered User

 
Join Date: Jan 2016
Location: Cheshire, UK
Posts: 9
lol... would SystemTagList do the job if it wasn't for the PROGDIR: issue..?
SavageMonkey is offline  
Old 11 August 2018, 20:26   #15
Don_Adan
Registered User
 
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 50
Posts: 959
Quote:
Originally Posted by meynaf View Post
The fact a file exists doesn't make it a valid executable.
You can check, if existed file is executable, this is easy enough. Check for $000003f3 at begin and $000003f2 at end of file. And for kick 2.0+ you must check also for R and E bits.
Don_Adan is offline  
Old 11 August 2018, 20:37   #16
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 45
Posts: 2,997
Quote:
Originally Posted by alkis View Post
Autodocs on execute say the result is bool on if it found and executed the prorgam or not.

http://amigadev.elowar.com/read/ADCD.../node015E.html

That does not apply?
I don't know what return code it gives, but when i saw the error message in the cli i knew it did not work as i wanted...


Quote:
Originally Posted by SavageMonkey View Post
lol... would SystemTagList do the job if it wasn't for the PROGDIR: issue..?
Nope - it also shows bogus error message in cli.


Quote:
Originally Posted by Don_Adan View Post
You can check, if existed file is executable, this is easy enough. Check for $000003f3 at begin and $000003f2 at end of file. And for kick 2.0+ you must check also for R and E bits.
That's quite a weak check, and will catch libraries, devices, handlers, etc, as well as malformed executables.


Oh, yes, just to add to the horror of it... It seems LoadSeg() will probably not apply to internal (rom) commands. Neither would checking if file exists, of course
meynaf is offline  
Old 11 August 2018, 22:40   #17
Don_Adan
Registered User
 
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 50
Posts: 959
Quote:
Originally Posted by meynaf View Post
I don't know what return code it gives, but when i saw the error message in the cli i knew it did not work as i wanted...



Nope - it also shows bogus error message in cli.



That's quite a weak check, and will catch libraries, devices, handlers, etc, as well as malformed executables.


Oh, yes, just to add to the horror of it... It seems LoadSeg() will probably not apply to internal (rom) commands. Neither would checking if file exists, of course
No, this is good/enough test. All good written libraries, devices, handlers will be not crashed after running, because has moveq #x,D0, rts at begining. And remember dont exist 100% test for crash protection. Someone can put trash data inside code, or one bit can be changed in code when file was copying (it occured often for weak HD or DD or damaged RAM). Od course you can add more tests for object files, more hunks to check or check if first called data is valid 68k command.

But of course if you want to be perfect, you can add CRC check for every file and ignore files within wrong CRC.
Don_Adan is offline  
Old 11 August 2018, 22:56   #18
Don_Adan
Registered User
 
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 50
Posts: 959
And of course, all valid Amiga exe files packed with absolute addressing mode or which used direct access to VBR = 0, will be crash Amiga too. Then only solution is checking CRC or something similar.
Don_Adan is offline  
Old 12 August 2018, 09:36   #19
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 45
Posts: 2,997
The problem isn't a potential crash. The problem is bogus error message appearing on cli when the command can't be loaded. Libraries, etc, have moveq #-1,d0+rts at start and this *will* trigger the message even though the exe is perfectly valid.
meynaf is offline  
Old 12 August 2018, 16:59   #20
Don_Adan
Registered User
 
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 50
Posts: 959
Quote:
Originally Posted by meynaf View Post
The problem isn't a potential crash. The problem is bogus error message appearing on cli when the command can't be loaded. Libraries, etc, have moveq #-1,d0+rts at start and this *will* trigger the message even though the exe is perfectly valid.
Then check if first longword of running code is moveq #-1,d0, rts, and prevent this file from be called.
Don_Adan is offline  
AdSense AdSense  
 


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
** Stack Overflow ** trying to run program in WinUAE Audiorulz4u support.WinUAE 10 22 May 2018 22:05
ClassicWB: How to run a program at startup? Foebane support.Apps 20 05 March 2018 09:54
Run AREXX program from PC side? MickGyver support.WinUAE 5 15 March 2017 10:05
Possible to run a program from CLI in background? VoltureX support.Apps 17 14 January 2012 03:16
Cant run AnimatED....anyone every used this great program? mrbob2 support.Apps 2 20 June 2009 13:13

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 03:47.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.
Page generated in 0.12570 seconds with 14 queries