Pexec in HiSoft Basic anyone?

Post Reply
User avatar
robv
Captain Atari
Captain Atari
Posts: 307
Joined: Mon Nov 09, 2020 7:39 pm
Location: Netherlands

Pexec in HiSoft Basic anyone?

Post by robv »

I need to call an external program from HiSoft Basic and return to the running program. According to the (not faultless) manual Gemdos FUNCTION Pexec() should do it.
This is as far as I get, strictly following the manual

Code: Select all

LIBRARY "gemdos" 
DEFINT a-z
mode = 0
prg$ = "mytool.ttp" + CHR$(0)
cmd$ = "my command" + CHR$(0)
env$ = CHR$(0) + CHR$(0)
x = FUNCTION pexec(mode, prg$, cmd$, env$)
PRINT x
This will give me a

Code: Select all

ERROR: 46 Expression syntax at LINE 7
Tried several variations, with or without null termination, without success.
Any HBASIC user who can help me out?
Rob
engaged with Atari ST since 1987
http://acwot.st
User avatar
lp
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2821
Joined: Wed Nov 12, 2003 11:09 pm
Location: GFA Headquarters
Contact:

Re: Pexec in HiSoft Basic anyone?

Post by lp »

Barely used HiSoft, but "FUNCTION" looks out of place, try:
x = pexec(mode, prg$, cmd$, env$)
User avatar
robv
Captain Atari
Captain Atari
Posts: 307
Joined: Mon Nov 09, 2020 7:39 pm
Location: Netherlands

Re: Pexec in HiSoft Basic anyone?

Post by robv »

Thanks, that takes me one step further.

Code: Select all

LIBRARY "gemdos" 
REM $OPTION k50
DEFINT a-z
DECLARE FUNCTION pexec(mode, prg$, cmd$, env$)
mode = 0
prg$ = "E:\HBASIC\MYTOOL.TOS"
cmd$ = ""
env$ = ""
x = pexec(mode, prg$, cmd$, env$)
Now I can compile it, but get an error when running
Sub-program not present
Path is correct. Maybe the program does not get loaded?
Rob
engaged with Atari ST since 1987
http://acwot.st
User avatar
lp
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2821
Joined: Wed Nov 12, 2003 11:09 pm
Location: GFA Headquarters
Contact:

Re: Pexec in HiSoft Basic anyone?

Post by lp »

Don't know if the command internally adds the required nulls. If the null isn't added it might not see the path correctly. Try adding the null, it shouldn't hurt anything, since the string is passed via address.
User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 3456
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: Pexec in HiSoft Basic anyone?

Post by charles »

theres a hisoft pdf somewhere around here , very user friendily manual
its focus is for v 2 and from my use of h.s.basic or power basic or first basic is 2nd version is different from first

ill try to dig it up and show link or ill snap photo of my manual

Charles
The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!
User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 3456
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: Pexec in HiSoft Basic anyone?

Post by charles »

REM $option k100
REM $option !gy

DEFINT a-z

LIBRARY "gemaes","gemdos"

REM $include gemaes.bh

FUNCTION GetWholeEnvironment$
STATIC i,res$,a$
res$=""
i=1
DO
a$=ENVIRON$(i)
IF a$="" THEN EXIT LOOP
res$=res$+a$+CHR$(0)
INCR i
LOOP
GetWholeEnvironment$=res$
END FUNCTION

FUNCTION killpath$ (path$)
STATIC i,ch
i=LEN(path$)
DO
ch=ASC(MID$(path$,i,1))
IF ch="\"% OR ch=":"% THEN EXIT LOOP
IF i=1 THEN EXIT LOOP
DECR i
LOOP
killpath$=LEFT$(path$,i)
END FUNCTION

FUNCTION killname$ (path$)
STATIC i,ch,dummy$
i=LEN(path$)
DO
ch=ASC(MID$(path$,i,1))
IF ch="\"% OR ch=":"% THEN EXIT LOOP
IF i=1 THEN EXIT LOOP
DECR i
LOOP
dummy$=RIGHT$(path$,i)

i=LEN(dummy$)
DO
ch=ASC(MID$(dummy$,i,1))
IF ch="."% THEN EXIT LOOP
IF i=1 THEN EXIT LOOP
DECR i
LOOP
killname$=LEFT$(dummy$,i-1)+" "
END FUNCTION

SUB Execute(nname$,commline$)
SHARED menutree&
STATIC junk&,junk,curhandle,i,curtop
STATIC dummypath1$,dummypath2$,dummydrive,pe,mxprogs
STATIC WindX,WindY,WindW,WindH,cur_top

mxprogs=PEEKW(PEEKL(GB+4)+ap_count)
pe=0
IF mxprogs=-1 THEN pe=100

junk=wind_get (0,WF_WORKXYWH,WindX,WindY,WindW,WindH)
junk=wind_get (0,WF_TOP,cur_top,0,0,0)

dummypath1$=killpath$ (nname$)
dummypath2$=CURDIR$
dummydrive=dgetdrv

junk=dsetdrv (ASC(MID$(dummypath1$,1,1))-ASC("A"))
CHDIR dummypath1$

junk&=pexec&(pe,nname$,commline$,GetWholeEnvironment$)

junk=dsetdrv (dummydrive)
CHDIR dummypath2$

junk=wind_set (0,WF_TOP,cur_top,0,0,0)
form_dial FMD_FINISH,0,0,0,0,WindX,WindY,WindW,WindH

END SUB

SUB va_send (to$,commline$)
STATIC a$,a&,c$,c&,i,junk

a$=SPACE$(16) : a&=VARPTR(a$)
'c$="H:\MODS\INTRO.MOD"+CHR$(0) : c&=VARPTR(c$)
c$=commline$+CHR$(0) : c&=VARPTR(c$)

i=appl_find(to$)

IF i=-1 THEN junk=form_alert (1,"[1][ VA server not found! ][ OK ]")

IF i<>-1 THEN
POKEW a&,&H4711
POKEW a&+2,PEEKW(PEEKL(GB+4)+4)
POKEW a&+4,0
POKEL a&+6,c&
POKEW a&+10,0
appl_write i,16,a&
END IF
END SUB


SUB ViewFileMulti (filename$,comm$)
STATIC mxprogs,editorva$,junk

mxprogs=PEEKW(PEEKL(GB+4)+ap_count)

IF filename$="" THEN
junk=form_alert (1,"[1][ No editor set! ][ OK ]")
ELSE
IF mxprogs=-1 THEN
editorva$=killname$ (filename$)
IF appl_find (editorva$)<>-1 THEN ' ie program already running
CALL va_send (editorva$,comm$)
ELSE
CALL Execute (filename$,comm$)
END IF
ELSE
CALL Execute (filename$,comm$)
END IF
END IF

END SUB

a$="D:\EVEREST\EVEREST.PRG"
b$="C:\EMAIL.TXT"
CALL ViewFileMulti (a$,b$)
er=form_alert (1,"[1][ Finished ][ OK ]")
STOP -1
The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!
User avatar
lp
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2821
Joined: Wed Nov 12, 2003 11:09 pm
Location: GFA Headquarters
Contact:

Re: Pexec in HiSoft Basic anyone?

Post by lp »

Not sure what manual you are using, but mine says something about pexec() falling if the calling program doesn't leave the operating system enough free ram to execute the requested program.
User avatar
robv
Captain Atari
Captain Atari
Posts: 307
Joined: Mon Nov 09, 2020 7:39 pm
Location: Netherlands

Re: Pexec in HiSoft Basic anyone?

Post by robv »

charles wrote: Sat Jan 16, 2021 2:46 am theres a hisoft pdf somewhere around here , very user friendily manual
I use the ones on dev-docs https://docs.dev-docs.org/htm/search.php?find=hisoft, probably the same.
Thanks to your elaborate example I found the problem. According to the manual the call is pexec%() but that won't work. However pexec&() does 8) .
So the working code is

Code: Select all

LIBRARY "gemdos" 
REM $OPTION k50
mode = 0
prg$ = "E:\HBASIC\MYTOOL.TOS"
cmd$ = ""
env$ = ""
x& = pexec&(mode, prg$, cmd$, env$)
Rob
engaged with Atari ST since 1987
http://acwot.st
User avatar
robv
Captain Atari
Captain Atari
Posts: 307
Joined: Mon Nov 09, 2020 7:39 pm
Location: Netherlands

Re: Pexec in HiSoft Basic anyone?

Post by robv »

lp wrote: Sat Jan 16, 2021 5:28 am Not sure what manual you are using, but mine says something about pexec() falling if the calling program doesn't leave the operating system enough free ram to execute the requested program.
True. HBasic has those weird compiler directives that look like remarks to take care of that. I use

Code: Select all

REM $OPTION k50
to limit the program to 50K and leave the rest to the system.
But, as stated above, the true problem was a misprint in the manual :x
Rob
engaged with Atari ST since 1987
http://acwot.st
User avatar
lp
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2821
Joined: Wed Nov 12, 2003 11:09 pm
Location: GFA Headquarters
Contact:

Re: Pexec in HiSoft Basic anyone?

Post by lp »

Well I would not have spotted the "%" versus "&" issue. Not sure what that even implies. The GFA manual also has it's share of quirks. ;)
Last edited by lp on Sat Jan 16, 2021 10:29 pm, edited 1 time in total.
User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 3456
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: Pexec in HiSoft Basic anyone?

Post by charles »

and this is a great example on how every one should submit their code
because lost documents or misdirection leave use of programs clueless
but more importantly broadens user base making us a stronger collective.
The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!
User avatar
robv
Captain Atari
Captain Atari
Posts: 307
Joined: Mon Nov 09, 2020 7:39 pm
Location: Netherlands

Re: Pexec in HiSoft Basic anyone?

Post by robv »

charles wrote: Sat Jan 16, 2021 2:13 pm and this is a great example on how every one should submit their code
because lost documents or misdirection leave use of programs clueless
but more importantly broadens user base making us a stronger collective.
Agree. So here's another HiSoft Basic quirk I encountered:
Some calls in their Gemdos lib are defined as FUNCTION, others as SUB. You can call a function just by its name

Code: Select all

x&=pexec&(..)
But you can call a sub just by its name only when you're passing none or just one argument. If you need to pass more than one you need to add CALL.
This is the code I use now for calling a TOS program and redirecting its output to NULL (using fforce() ). Mode 100 means load, go, don't wait
http://toshyp.atari.org/en/00500b.html#Pexec

Code: Select all

LIBRARY "gemdos" 
REM $OPTION k50
DEFINT a-z
CALL fforce(1,-4)
mode = 100
prg$ = "gapftp.ttp"
cmd$ = "-s:minipos.ftp"
env$ = ""
x& = pexec&(mode, prg$, cmd$, env$)
PRINT "Ready!"
Rob
engaged with Atari ST since 1987
http://acwot.st
czietz
Hardware Guru
Hardware Guru
Posts: 2819
Joined: Tue May 24, 2016 6:47 pm

Re: Pexec in HiSoft Basic anyone?

Post by czietz »

Be aware, though, that Pexec modes 100 and above are just available under multitasking operating systems (MagiC, maybe MiNT) and not under plain TOS.
neanderthal
Captain Atari
Captain Atari
Posts: 367
Joined: Sun Jul 10, 2016 10:58 pm

Re: Pexec in HiSoft Basic anyone?

Post by neanderthal »

lp wrote: Sat Jan 16, 2021 1:40 pm Well I would not have spotted the "%" versus "&" issue. Not sure what that even implies. The GFA manual also has it share of quirks. ;)
Is that a HSBasic sort of thing me wonders,I mean never done anything more than 'hello world' thingy in basic itself even if figured out how to do c-style asm calls some years back in HSBasic XD
Kinda neat trick btw.
Anywho,gets me to think of C and adresses with the &.

And about the REM thing,that sounds real odd to me that parameters of that kind is passed on as 'reminders' or whatever REM stands for?
Playmobil
Captain Atari
Captain Atari
Posts: 295
Joined: Fri Nov 13, 2015 7:40 pm

Re: Pexec in HiSoft Basic anyone?

Post by Playmobil »

The best way is : Coding in GFA-Basic ! :mrgreen: :lol: :mrgreen:
neanderthal
Captain Atari
Captain Atari
Posts: 367
Joined: Sun Jul 10, 2016 10:58 pm

Re: Pexec in HiSoft Basic anyone?

Post by neanderthal »

Playmobil wrote: Sat Jan 16, 2021 8:57 pm The best way is : Coding in GFA-Basic ! :mrgreen: :lol: :mrgreen:
Came to think of it,might have been GFA did the c-call thing in ??..Have to check the machine for that ..lol
User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 3456
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: Pexec in HiSoft Basic anyone?

Post by charles »

gfa did exec if I recall
The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!
Post Reply

Return to “Other BASIC”