View Complete Thread | FoxWeb Forum Home
Search:
Date:    Msg ID:   
From:    Thread:   
Subject:   
This worked great, thanks for the help.

Sent by Oleg Goncharuk on 02/08/2002 08:27:20 AM:
When I need to run foxpro program in separate thread I usualy compile it in  .EXE file (it needs separate VFP project for this) and run with RUN command. It works perfectly for me.
But if I wish to run PRG files, I use a custom class method from my library (that works with VFP6 SP3 and up). The method works both with VFP.exe and VFP run-time.
I read PRG into memory using FILETOSTRING and then run it directly from memory variable. Using this technique it is possible to run memo fields or even construct foxpro scripts on the fly.

Here is code for method:
*********************************************************
*FUNCTION ExecPRG
* First parameter - Foxpro code
* The rest are optional parameters (upTo seven)
*
*****************************************************
PARAMETERS cProc,Param1,Param2,Param3,Param4,Param5,Param6,Param7
LOCAL cRes,cCode,cFile,cDir
cRes=""
IF !EMPTY(cProc)
  IF VERSION(5)>=700  && VFP7 supports it natively
    cDir=CURDIR()
     cRes=EXECSCRIPT(cProc,Param1,Param2,Param3,Param4,Param5,Param6,Param7)
    SET DEFAULT TO (cDir)
  ELSE
    cDir=CURDIR()
    cCode=FORCEEXT(ALLT("F"+SYS(2015)),"prg")  &&We need some trick to make it Run on VFP6
    STRTOFILE(cProc,cCode)
    COMPILE &cCode
    cProc=JUSTSTEM(cCode)+"(Param1,Param2,Param3,Param4,Param5,Param6,Param7)"
    cRes=&cProc
    SET DEFAULT TO (cDir)
    cFile=FORCEEXT(cCode,"prg")
    ERASE &cFile
    cFile=FORCEEXT(cCode,"fxp")
    ERASE &cFile
    IF TYPE("cRes")<>"C"
      cRes=Server.ToString(cRes)
    ENDIF
  ENDIF
ENDIF
RETURN cRes

Sent by Joe Cosby on 02/06/2002 11:07:03 AM:
I seem to have trouble with this.  In a Foxpro program I set the default directory to the foxpro install directory and then give it a

RUN /N vfp6.exe x:\programpath\foo\myprogram.prg

When I run this program from a Foxpro instance on the same machine as is running the CGI server, it works, "myprogram.prg" is open in a new foxpro instance.  When exactly the same program is called via foxweb, a new foxpro instance opens but it exits immediately.

I also tried doing this with a batch file.  From the foxpro program I called a batch file, and the batch file called foxpro with the "myprogram.prg" argument.  When this batch file was run from Windoze it worked as designed, called FP and ran the prg.  Likewise when the program which calls the batch file was run from a foxpro instance, it worked right.  When the same program was called from foxweb, it ran the batch file (I put a long 'type' command in so I could verify it ran) but FP didn't run the program.

Has anybody done something like this succesfully before?

***

The general idea is, I'm trying to work around the lack of any support for threads in foxpro.  This is the only approach I've been able to find.  If anybody else has come up with some approach to launching a foxpro process as a separate thread (other than the above) that would be helpful too.

***

Any help would be greatly appreciated, thanks.