Best way to call an EXE

Topics: Developer Forum, User Forum
Nov 13, 2014 at 3:40 PM
Hi All

This is my first post and I am very excited to begin using AVFP. I have a desktop app that I now want to expand to the web. To begin I am hoping that I can build upon some of the functionality in the desktop app and bring it to the web.

For example, the current app can run in a silent mode to output a specified report to a PDF file for viewing...

c:\path\myapp.exe par1 par2 par3

What would you recommend is the best approach to run an EXE and wait for it to finish (could take 2-10 seconds)? Is the code sample for Async Processing something I should look at? Thanks so much!
Nov 14, 2014 at 8:58 AM
Hi Robert,

For PDF, check out the PDF demo and code.

The standard way to call the EXE from AVFP is to make the VFP EXE a COM EXE VFP, instantiate it via CREATEOBJECT in avfp, and call its methods to perform VFP Report generation and PDF generation.
Nov 14, 2014 at 4:10 PM
Hi Claude

Thanks for your reply. I am going to try a few different things to see what works best. The current desktop application and it's database (tables) could reside on the same server as IIS but more than likely on a different one. I am not familiar with ASP.NET but I did come across this below and I will play around to see if it is something I can use.

System.Diagnostics.Process process1 = new System.Diagnostics.Process();
process1.StartInfo.FileName = @"c:\temp\File1.exe"; process1.StartInfo.Arguments = "args";
Nov 14, 2014 at 5:08 PM
Ok, let us know if you need more help to get your application ported to web (and/or mobile). We just did a web VFP Order Entry system for a huge company and are currently working on an extremely cool jQuery Mobile version of an existing VFP restaurant point of sale system. THe waiter\waitress will take orders via iPhone or iPad and send to kitchen - using existing VFP code and data on the backend!
Nov 19, 2014 at 3:32 PM
Hi Claude

Back again. I am able to do what I want using the ASP.NET Process class (as show above). The code runs fine when executed from a separate IIS application meaning there are no ties to AVFP. However I get an error if I try to run the ASPX code file from AVFP code page using the Demo application. Is there something simple I am missing to do this. Thanks.

<input type="button" value="Run ASPX" onClick="window.location = '<%=JustPath(oProp.ScriptPath)+[/testpdf.aspx%>

Here is the error...

Caught .NET exception, source: TESTPDF.ASPX mergescript err#= 10 Syntax error. Compilation Error: Syntax error in the script (TESTPDF.ASPX)that was called. 10 Syntax error. .NULL. .NULL. .NULL. .NULL. .NULL. c:\ActiveVFP\activevfp.dll message: c:\ActiveVFP\activevfp.dll
Nov 20, 2014 at 8:18 PM
I guess my question is "Can you instantiate a .NET class from AVFP or is there a work around"?
Nov 21, 2014 at 8:51 AM
you could use Dotnetbridge to call anything in .net

but seems like a roundabout way of getting a simple thing done

Making the fox exe a com exe and calling it from activevfp seems far more straightforward and simpler
Nov 21, 2014 at 3:25 PM
Hi Claude

One last thing before I decide what is the best approach. Am I correct in saying you cannot execute a ASPX page (includes C# scripting language) from a AVFP page because it is expected to be compiled by activevfp.dll? The ActiveVFP demo includes a HELLO.AVFP and HELLO.ASPX. Is there no way to execute the HELLO.ASPX page so it bypasses the AVFP compiler? Thanks.
Nov 21, 2014 at 3:35 PM
Edited Nov 21, 2014 at 3:36 PM
Well if you just include a regular link to a .aspx page (or any kind of page) from an AVFP page there should absolutely be no problem.

Are you saying you get an error when you do that?

If this is the case, it may have something to do with the web.config we use for AVFP. If you place the page with the C# code in another folder (not the same folder as AVFP) then that should work because it would NOT use our web.config since it's not in the AVFP folder. The web.config modifies the .NET environment.

Sorry if I misunderstood the problem if this is the case.
Nov 21, 2014 at 4:09 PM
Thanks. Just ran a test and I do not get an error if I place the code in another application (non AVFP) folder. It would be nice if I can include the C# page in the AVFP folder for client distribution down the road.

If and when you have some free time maybe you can explain how this can be done. Much appreciated.
Nov 21, 2014 at 6:44 PM

I changed the Web.Config file as follows and I can now run ASPX code pages within the Demo app. Is this OK?

<add verb="*" path="*"
  <add verb="*" path="*.avfp"
Nov 22, 2014 at 12:22 PM
As long as it works with what you're doing, it should be fine.
Dec 1, 2014 at 11:00 PM
Hi robert27..

Just a few minor points you may like to keep in mind before settling on changing the config file.
  1. Extension less calls are a nice feature in AVFP. You may require it down the road.
  2. REST module is also nice, if u plan on using Ajax. I generally open the page with regular extension less URL.. then do all the POST/GET activity using Ajax. This keeps both SEO and security people happy.
Maybe.. u may like explore allowing ASPX specifically.. rather than AVFP.