Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to suppress the DOS prompt
Message
 
À
07/07/2009 03:29:08
Yim Ming Sun Derek
Spacious Design Consultant
Hong Kong, Hong Kong
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows 2000 SP4
Network:
Windows 2003 Server
Database:
Visual FoxPro
Divers
Thread ID:
00971249
Message ID:
01410487
Vues:
77
Hi Derek,

This is a function that I use to execute an application and wait for the result:
*========================================================================================
* Executes another application, waits for it to complete and returns the error level
*========================================================================================
LParameter tcCmdLine

	*--------------------------------------------------------------------------------------
	* API declarations
	*--------------------------------------------------------------------------------------
	DECLARE INTEGER CreateProcess IN kernel32.DLL ;
		String lpApplicationName, ;
		STRING lpCommandLine, ;
		INTEGER lpProcessAttributes, ;
		INTEGER lpThreadAttributes, ;
		INTEGER bInheritHandles, ;
		INTEGER dwCreationFlags, ;
		String lpEnvironment, ;
		String lpCurrentDirectory, ;
		STRING @lpStartupInfo, ;
		STRING @lpProcessInformation
	Declare long GetLastError in Win32API

	*--------------------------------------------------------------------------------------
	* Launch the application
	*--------------------------------------------------------------------------------------
	Local lcStartupInfo, lcProcessInfo, lnOK
	lcStartupInfo = ;
		BINTOC(68,"RS") + ;
		Replicate(Chr(0),40) + ;
		BinToC(1,"RS") + ;
		BinToC(0,"2RS") + ; && SW_HIDE
		BinToC(0,"2RS") + ;
		Replicate(Chr(0),16)
	lcProcessInfo = Replicate(Chr(0),16)
	lnOK = CreateProcess( ;
		NULL, ;
		m.tcCmdLine, ;
		0, ;
		0, ;
		1, ;
		0x20, ;
		NULL, ;
		NULL, ;
		@lcStartupInfo, ;
		@lcProcessInfo ;
	)

	*--------------------------------------------------------------------------------------
	* Extract the handles from the PROCESSINFO structure
	*--------------------------------------------------------------------------------------
	Local lnProcessHandle, lnThreadHandle
	If m.lnOK == 0
		Return -1
	Else
		lnProcessHandle = CTOBIN(Substr(m.lcProcessInfo,1,4),"RS")
		lnThreadHandle = CTOBIN(Substr(m.lcProcessInfo,5,4),"RS")
	EndIf 

	*--------------------------------------------------------------------------------------
	* Wait for the process to terminate
	*--------------------------------------------------------------------------------------
	Declare Long WaitForSingleObject in Win32API Long, Long
	WaitForSingleObject( m.lnProcessHandle, -1 )
	
	*--------------------------------------------------------------------------------------
	* Get the error code
	*--------------------------------------------------------------------------------------
	Local lnExitCode
	lnExitCode = -1
	Declare Long GetExitCodeProcess in Win32API ;
	  Long hProcess, ;
  	Long @lpExitCode
	GetExitCodeProcess( m.lnProcessHandle, @lnExitCode )

	*--------------------------------------------------------------------------------------
	* Close handles
	*--------------------------------------------------------------------------------------
	Declare CloseHandle in Win32API Long
	CloseHandle( m.lnProcessHandle )
	CloseHandle( m.lnThreadHandle )

Return m.lnExitCode
--
Christof
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform