Hi Przemek,
is it possible to add below function ?
hb_ProcessIsRunning( hProc, nTimeoutMsecs ) -> lIsRunning
to check if a process started with hb_ProcessOpen() is currently running
so I can have:
PROC Main()
LOCAL hOut
LOCAL hProc := hb_ProcessOpen( "test.exe",, @hOut, @hOut, .T. )
LOCAL nStart := hb_milliseconds()
LOCAL cDate, cOutPut, nLen
IF hProc > -1
DO WHILE .T.
cData := Space( 1000 )
cOutPut := ""
DO WHILE ( nLen := Fread( hOut, @cData, Len( cData ) ) ) > 0
cOutPut += SubStr( cData, 1, nLen )
cData := Space( 1000 )
ENDDO
IF !hb_ProcessIsRunning( hProc, 0 )
EXIT
ENDIF
IF ( hb_milliseconds() - nStart ) > 30 * 1000
// Kill process
HB_ProcessClose( hProc )
ENDIF
ENDDO
HB_ProcessValue( hProc )
ENDIF
RETURN
Without need to handle it in MT mode using another thread as I did in
uhttpd and using above code in ST mode.
I looked at hbproces.c code and Windows (HB_IO_WIN) version I suppose
could be this:
int hb_fsProcessIsRunning( HB_FHANDLE hProcess, DWORD dwTimeout )
{
BOOL fRunning = FALSE;
HB_TRACE(HB_TR_DEBUG, ("hb_fsProcessIsRunning(%p, %d)", ( void * ) (
HB_PTRDIFF ) hProcess, dwTimeout));
{
DWORD dwResult;
HANDLE hProc = ( HANDLE ) hb_fsGetOsHandle( hProcess );
if( hProc )
{
hb_vmUnlock();
dwResult = WaitForSingleObject( hProc, dwTimeout );
if ( dwResult != WAIT_OBJECT_0 )
fRunning = TRUE;
hb_vmLock();
}
else
hb_fsSetError( ( USHORT ) FS_ERROR );
}
return fRunning;
}
and for hbprocfn.c
HB_FUNC( HB_PROCESSISRUNNING )
{
HB_FHANDLE hProcess = hb_numToHandle( hb_parnint( 1 ) );
if( hProcess != 0 && hProcess != FS_ERROR && ( hb_pcount() < 2 ||
ISNUM( 2 ) ) )
hb_retni( hb_fsProcessValue( hProcess, ( hb_pcount() < 2 ? 0 :
hb_parnint( 2 ) ) ) );
else
hb_errRT_BASE_SubstR( EG_ARG, 4001, NULL, HB_ERR_FUNCNAME,
HB_ERR_ARGS_BASEPARAMS );
}
but for other OSes I don't know how handle it.
Could you kindly help me ?
TIA
Best Regards,
Francesco
_______________________________________________
Harbour mailing list
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour