>Hi to all
>
>How can we do to call an .EXE file from another .EXE file passing it a parameter?
>
>Both .EXEs are generated with Visual FoxPro 5.0
It depends on how you're launching the second application; you can pass parameters on the command line (you'll need an appropriate LPARAMETERS or PARAMETERS statement in the main module to capture the values passed in) if you use RUN or an API call like CreateProcess() or ShellExecute().
In order to allow for command line parameters, the first executable line in your main .PRG should be a PARAMETERS statement; you can check the number of parameters passed in using PCOUNT() as usual. Command line parameters are always accepted as string values when passed to an .EXE.
For example, to start an executable from VFP, and pass the content of the string variable cMyVar as a parameter, you could say:
RUN MyApp.EXE &cMyVar
If cMyVar contains spaces, make certain to encapsulate the value in double quotes, or the Windows command processor will parse it into multiple arguments; you might want to say:
cMyCommandLine = 'RUN MyApp.EXE "' + cMyVar + '"'
&cMyCommandLine
You can also invoke a VFP .EXE using DO; you pass values to the .EXE like you would pass them to any other piece of VFP code:
DO MyApp.EXE WITH cMyVar
Realize that this runs the .EXE in the current VFP session; if the other application makes changes to the runtime environment, or issues a QUIT, it will affect the currently-running application. You can pass variables of any type into an .EXE started with a DO.
The difference here is quite striking; if your MAIN.PRG starts like:
LPARAMETER uParm1
WAIT WINDOW TYPE('uParm1')
If you invoke it by saying
RUN MyApp.EXE 1, the wait window will display "C"; it'll be a 1 character string. If instead you say
DO MyApp.EXE WITH 1, the wait window will display "N", and the parameter will be a number rather than a string.
Finally, if the second .EXE is an out-of-process server created with VFP, you'd communicate with it through the OLE interface defined for the OLE Automation server after you do a CREATEOBJ() or GETOBJECT() (or NEWOBJECT() in VFP 6.)
Ed