Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Pausing for completion of a RUN command
Message
From
21/11/2006 11:08:36
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
20/11/2006 14:17:07
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 8 SP1
Miscellaneous
Thread ID:
01171227
Message ID:
01171459
Views:
21
Tracy,
Have you ever tried this with office applications like word? Last time I tried to build something around this it was failing (one of the instances were returning immediately - word behaves like an MDI while Excel like an SDI) if I call it for a 2nd instance of word and I gave up.
Cetin


>Can you use createprocess instead? If so, you can wait for it to finish.
>
>*---Example and running an external app and holding processing in VFP until finished
>*
>lcApp="NotePad.exe"         && app to run
>lcCmdLine="myfile.txt"      && file to open in notepad
>lcdir="c:\windows\"	    && not required for notepad
>
>llokay = ExeWait(lcApp,lcCmdLine,lcdir)
>IF !llokay
>   =MESSAGEBOX('An error ocurred.')
>ELSE
>   =MESSAGEBOX('Program is closed, returned to vfp')
>ENDIF
>
>RETURN
>
>*----------------------------------------------------------------------
>PROCEDURE  ExeWait (lcApp, lcCmdLine, lcdir)
>DO DECLexewait  && load required dlls for exewait function
>PRIVATE lntimes
>lntimes = 0
>IF _VFP.AUTOYIELD = .F.
>    llsetback = .T.
>ELSE
>    llsetback = .F.
>ENDIF
>_VFP.AUTOYIELD = .T.
>PRIVATE lnclosepass
>lnclosepass = 0
>#DEFINE INFINITE  0xFFFFFFFF
>LOCAL lcStartupInfo, lcProcInfo, hProcess, ;
>    lnPrio, lnIBelieve1
>lnIBelieve1 = 1   && Don't remember what that was
>lnPrio = 32 && Priority of Process=Normal
>lcStartupInfo = CHR(68) + REPLI(CHR(0), 67)
>lcProcInfo = REPLI(CHR(0), 16)
>IF CreateProcess(0, m.lcApp+" "+m.lcCmdLine+CHR(0), 0,0,;
>        m.lnIBelieve1, m.lnPrio,;
>        0, 0, @lcStartupInfo, @lcProcInfo) <> 0
>    * process and thread handles returned in ProcInfo structure
>    hProcess = buf2dword(SUBSTR(lcProcInfo, 1,4))
>    hThread = buf2dword(SUBSTR(lcProcInfo, 5,4))
>    * waiting until the termination of the program
>    DOEVENTS
>    DO WHILE .T.
>       exitcode = 0                    && initialize return value to 0
>       = GetExitCodeProcess(hProcess, @exitcode)    && try to obtain process exit code
>       IF exitcode # 259                && not still busy
>           EXIT                            && fall out of loop
>       ENDIF
>       = Sleep (100)                    && wait .1 seconds
>    ENDDO
>    = CloseHandle(hThread)
>    = CloseHandle(hProcess)
>ELSE
>    IF llsetback
>        _VFP.AUTOYIELD = .F.
>    ENDIF
>    RETURN .F.
>ENDIF
>IF llsetback
>    _VFP.AUTOYIELD = .F.
>ENDIF
>DO RELexewait  && release dlls for exewait function
>RETURN
>
>*----------------------------------------------------------------------
>PROCEDURE DECLexewait  && load required dlls for exewait function
>=ADLLS(dllarray)
>IF TYPE('ALEN(dllarray,1') <> "N" .or. ASCAN(dllarray,'CREATEPROCESS') = 0
>	DECLARE INTEGER CreateProcess IN kernel32;
>		INTEGER lpAppName, STRING lpCmdLine, INTEGER lpProcAttr,;
>		INTEGER lpThrAttr, INTEGER bInhHandles, INTEGER dwCrFlags,;
>		INTEGER lpEnvir, INTEGER lpCurDir, ;
>		STRING @lpStInfo, STRING @lpProcInfo
>ENDIF
>IF TYPE('ALEN(dllarray,1') <> "N" .or. ASCAN(dllarray,'GETLASTERROR') = 0
>	DECLARE INTEGER GetLastError IN kernel32
>ENDIF
>IF TYPE('ALEN(dllarray,1') <> "N" .or. ASCAN(dllarray,"CLOSEHANDLE") = 0
>	DECLARE INTEGER CloseHandle IN kernel32 INTEGER hObject
>ENDIF
>IF TYPE('ALEN(dllarray,1') <> "N" .or. ASCAN(dllarray,"GETEXITCODEPROCESS") = 0
>	DECLARE INTEGER GetExitCodeProcess IN WIN32API INTEGER hProcess, INTEGER @lpExitCode
>ENDIF
>IF TYPE('ALEN(dllarray,1') <> "N" .or. ASCAN(dllarray,"SLEEP") = 0
>	DECLARE Sleep IN kernel32 INTEGER dwMilliseconds
>ENDIF
>RETURN
>
>*----------------------------------------------------------------------
>PROCEDURE RELexewait  && release dlls for exewait function
>
>CLEAR DLLS CreateProcess
>CLEAR DLLS GetLastError
>CLEAR DLLS CloseHandle
>CLEAR DLLS GetExitCodeProcess
>CLEAR DLLS Sleep
>
>RETURN
>
>*----------------------------------------------------------------------
>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
>
>
>>Hi all
>>
>>I am running a RUN command to Export a File from a PDA for stocktaking. After i issue
>>the RUN command, I then import the delimited into a table. However, I would like the import
>>command to wait until the system has finish downloading the file from the handheld, otherwise the downloading is not complete when I am importing . Any ideas ?
>>
>>Brian O Donovan
Ç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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform