Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Calling a exe from within VFP with parameters
Message
De
17/02/2017 08:07:59
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012 R2
Network:
Windows Server 2012 R2
Database:
Visual FoxPro
Application:
Desktop
Virtual environment:
VMWare
Divers
Thread ID:
01648061
Message ID:
01648076
Vues:
82
>I need to call an exe from within VFP program and send the exe an argument and the receives a value back and depeding on the value I want to continue execution of the program.
>
>I am currently doing this
>
> lcApp = ALLTRIM(fold_loc) + ALLTRIM(exe_name)
> lcParam = ALLTRIM(exe_param)
> shellExecute (0,"", lcApp, lcParam,"",1)
>
>However I cant receive the argument returned from the called application. Also shellexecute will not wait until the value is returned.
>
>Is this possible in VFP?

Hi Stuart,
I have created an Activex control for this and shared here:

https://drive.google.com/file/d/0B1Q5wGByMZM-Y3gwcHRyRFlzSVk/view?usp=sharing

I hope you can download using that link.

You can either choose to WAIT FOR EXIT, or continue your work and NOTIFIED VIA AN EVENT when it exists.


You need to register it with "regasm.exe" - available on every windows machine. If regasm is not in path already, its expected location is:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe

Assuming you extracted the files to c:\cbUtilities run this on command line:
regasm c:\cbUtilites\cbUtilities.dll /codebase
And here is one demo code for testing,
-This would launch Notepad,
-Then start printing a message on VFP screen every 5 seconds just to show it is working independently,
-When notepad exists, it prints its exitcode, and also displays the contents of edited file in a message box.

(I assumed you had d:\temp folder already)
Local o As "cbNetCOM.Utilities", eh As 'cbUtilityEvents'
o = Createobject("cbNetCOM.Utilities")

Local lcFileName
m.lcFileName = 'd:\temp\seTest.txt'
Strtofile('',m.lcFileName)

eh=Createobject("cbUtilityEvents",m.o)
Eventhandler(m.o, m.eh)

o.ShellExecProcess("notepad.exe", m.lcFileName, .F., .F.)

* Shellexecuted the process
* Lets do some work while it is running
* Just to demonstrate it is async and we get the event 
* when it exists

Public oTimer as Timer
oTimer = CreateObject('myTimer')
m.oTimer.Enabled = .t.



Define Class myTimer as Timer
  Interval = 5000 && every 5 seconds
  Procedure Timer
    ? 'I am doing nothing useful, just hanging around.', Datetime()
  endproc
enddefine

Define Class cbUtilityEvents As Session OlePublic
	Implements IcbEvents In "C:\cbUtilities\CBUTILITIES.TLB"

	oHook = Null

	Procedure Init(toHook)
		This.oHook = m.toHook
	Endproc

	Procedure IcbEvents_OnProcessExit(ExitCode As Number, exitTime As Date, exceptionMessage As String) As VOID
		If Empty(m.exceptionMessage)
			? 'Process has exited on', m.exitTime, ' with exit code', m.ExitCode
			MessageBox(FileToStr('d:\temp\seTest.txt'))
		Else
			? 'Process had and exception. Message:', m.exceptionMessage
		Endif
		Eventhandler(This.oHook,This,.T.)
		This.oHook = Null
	Endproc

Enddefine
PS: Forgot to tell parameters (although intellisense names are self explanatory):
ShellExecProcess(fileNameToShellExec, cArguments [, [lHidden] [, lWaitToExit]] )
ileNameToShellExec: Exe filename (or something like mydocument.doc to invoke with associated application).
cArguments: command line arguments if any else pass an empty string.
lHidden: Default TRUE. Doesn't show a window.
lWaitToExit: Default TRUE. What for exit or not.
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform