Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
CreateProcess Problems
Message
De
20/11/2003 14:32:42
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Titre:
CreateProcess Problems
Divers
Thread ID:
00852013
Message ID:
00852013
Vues:
60
I can run a line from the dos command line and it works fine as follows :
cd \program files\ivans\transman.exe
Transman.exe /A /M:TECHSUPPORT;SYSERROR;TMCONFIG;AIDOWN
However, if I run it using createprocess as below, the transman.exe app starts as it should, but it does not function properly because the current directory is not getting set right. Can anyone see what I have done wrong? I've tried using CD and set default, etc and passing the folder to create process to no avail.

TIA
		DO DECL
		lcivansparm = " /A /M:TECHSUPPORT;SYSERROR;TMCONFIG;AIDOWN"
		*lcivansapp = get_ini(inifile,'[IVANS]','ExePath')
		*For testing and readabilty I will set the lcivansapp value myself
		lcivansapp = "c:\Program Files\IVANS\Transman\Transman.exe"
		lcivansdir = LEFT(lcivansapp,RAT("\",lcivansapp)-1)
		lcivansprg = "Transman.exe"
		CD (lcivansdir)
		SET DEFAULT TO LEFT(lcivansapp,RAT("\",lcivansapp)-1)
		IF FILE(lcivansdir+"\"+lcivansprg)
		     * I get here and run it fine but it does not function
                     = RunAndWait(lcivansprg, lcivansparm, lcivansdir)
                ENDIF
	   



PROCEDURE  RunAndWait (lcApp, lcCmdLine, lcdir)

		*lcdir is correct here - it is 
                *\program files\ivans\transman
                IF TYPE('lcdir')<>"C" .or. EMPTY(lcdir)
			lcdir = SYS(2003)
		ENDIF
		
		#DEFINE INFINITE  0xFFFFFFFF

		LOCAL lcStartupInfo, lcProcInfo, hProcess

		* creation of content for both structures is much simplified
		* for this particular example
		lcStartupInfo = CHR(68) + REPLI(CHR(0), 67)
		lcProcInfo = REPLI(CHR(0), 16)

*		IF CreateProcess(lcApp, lcCmdLine, 0,0,0,0,0, SYS(2003),;
*			lcStartupInfo, @lcProcInfo) <> 0

		IF CreateProcess(lcApp, lcCmdLine, 0,0,0,0,0, lcdir,;
			lcStartupInfo, @lcProcInfo) <> 0
			* retrieving handle for the new process
			hProcess = buf2dword(SUBSTR(lcProcInfo, 1,4))

			* waiting until the termination
			= WaitForSingleObject (hProcess, INFINITE)
			= CloseHandle (hProcess)
		ELSE
			RETURN GetLastError()
		ENDIF

	FUNCTION buf2dword(lcBuffer)
		RETURN ASC(SUBSTR(lcBuffer, 1,1)) + ;
		ASC(SUBSTR(lcBuffer, 2,1)) * 256 +;
		ASC(SUBSTR(lcBuffer, 3,1)) * 65536 +;
		ASC(SUBSTR(lcBuffer, 4,1)) * 16777216

	PROCEDURE DECL
		DECLARE INTEGER GetLastError IN kernel32
		DECLARE INTEGER CloseHandle IN kernel32 INTEGER hObject

		DECLARE INTEGER CreateProcess IN kernel32;
		STRING lpAppName, STRING lpCmdLine, INTEGER lpProcAttr,;
		INTEGER lpThrAttr, INTEGER bInhHandles, INTEGER dwCrFlags,;
		INTEGER @lpEnvir, STRING lpCurDir, STRING lpStInfo,;
		STRING @lpProcInfo

	DECLARE INTEGER WaitForSingleObject IN kernel32;
		INTEGER hHandle, INTEGER dwMilliseconds
		RETURN
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform