Hi Viktor,
For my part is no objection to incorporate _RunHide() in the
project, with the name you want and where you want.
http://groups.google.com/group/comp.lang.xharbour/browse_thread/thread/3378461f63826ce0/f842512cc396adf6#f842512cc396adf6
But I would like that a linux C coder adapt to the system.
Best regards,
Xavi
Szakáts Viktor escribió:
Hi Lorenzo,
There are some old tests that still use hb_run as "__hrbrun".
Well, that was not your point, but IMO __hrb*() functions should
be named hb_hrb*() since they are not really internal features
anymore.
Should we do it now?
Moreover we now have an util called hbrun which is more an "hrbrun".
Name stayed for compatibility reasons, I'd have better liked
hbdot, and it's still not too late to change it. If groups agreed
I can do it.
Sorry for the "word game", but I was looking for the differences
between __RUN and HB_RUN and it took me a while to get the right
info
so this may confuse users too.
I think the only difference is that HB_RUN() is in the documented
namespace, and it does return an errorlevel, while __RUN() is a
compatibility internal command with no return value. Otherwise
they do the same.
I was looking for it because I need to start an harbour app "in
background". Under Unix is as easy as add an "&" at the end of the
string but under Win you need sth like WinExec to achieve the same
result.
I wonder if instead of using sth like:
#if __PLATFORM__WINDOWS
WinExec( CmdStr )
#else
__RUN( CmdStr + " &" )
#endif
we could add a second parameter to HB_RUN like "fore/back" to get a
more elegant solution ( even because WinExec is not in std libs ).
For this I'd suggest to add something to hbw32.lib. Not only
background,
but also minimized, hidden, dont-wait-to-terminate (solvabe with
direct
CreateProcess() call only AFAIK) etc can be other options on Windows.
You might also already use ShellExecute(), this is also Win and even
shell specific, and not portable in a clean way.
Anyway, if there would be a portable way to solve any of this, it
would
be great, I agree.
Brgds,
Viktor
_______________________________________________
Harbour mailing list
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour
/*
* Harbour Project source code:
* _RUNHIDE & FILTEROUTCON functions
*
* Copyright 2008 Xavi <jarabal/at/gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/)
.
*
* As a special exception, the Harbour Project gives permission for
* additional uses of the text contained in its release of Harbour.
*
* The exception is that, if you link the Harbour libraries with other
* files to produce an executable, this does not by itself cause the
* resulting executable to be covered by the GNU General Public
License.
* Your use of that executable is in no way restricted on account of
* linking the Harbour library code into it.
*
* This exception does not however invalidate any other reasons why
* the executable file might be covered by the GNU General Public
License.
*
* This exception applies only to the code released by the Harbour
* Project under the name Harbour. If you copy code from other
* Harbour Project or Free Software Foundation releases into a copy of
* Harbour, as the General Public License permits, the exception does
* not apply to the code that you add in this way. To avoid misleading
* anyone as to the status of such modified files, you must delete
* this exception notice from them.
*
* If you write modifications of your own for Harbour, it is your
choice
* whether to permit this exception to apply to your modifications.
* If you do not wish that, delete this exception notice.
*
*/
#include "hbapi.h"
#include "hbapiitm.h"
#include "hbapierr.h"
/* TODO: S.O. Implementations. Now only Windows */
#include <windows.h>
/
*******************************************************************************
* RUN HIDE PROCESS CAPTURING OUTPUT
* ---------------------------------
* nRes := _RunHide( @cOut, cCmd )
*******************************************************************************/
#define DK_FACSIZE 4
#define DK_BUFSIZE 4096
HB_FUNC( _RUNHIDE )
{
char *cCmd = hb_parc(2);
PHB_ITEM pItmOut = hb_param( 1, HB_IT_STRING );
if( !cCmd || !pItmOut || !ISBYREF( 1 ) ){
hb_errRT_BASE_SubstR( EG_ARG, 3012, NULL, "_RUNHIDE", 2,
hb_paramError(1), hb_paramError(2) );
}else{
STARTUPINFO si;
SECURITY_ATTRIBUTES sa;
PROCESS_INFORMATION pi;
HANDLE hRPipe, hWPipe;
char *cOut, cBuffer[DK_BUFSIZE];
ULONG ulRes, ulBytes, ulRead, ulOff, ulMax;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;
if( !CreatePipe( &hRPipe, &hWPipe, &sa, 0 ) ){
hb_errRT_BASE_SubstR( EG_ARG, 0, "Create stdout pipe",
"_RUNHIDE", 0 ); return;
}
GetStartupInfo( &si );
si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
si.hStdOutput = si.hStdError = hWPipe;
si.hStdInput = NULL;
if( !CreateProcess( NULL, cCmd, NULL, NULL, TRUE,
DETACHED_PROCESS, NULL, NULL, &si, &pi ) ){
CloseHandle( hRPipe ); CloseHandle( hWPipe );
hb_errRT_BASE_SubstR( EG_ARG, 0, "CreateProcess",
"_RUNHIDE", 0 ); return;
}
ulOff = hb_itemGetCLen( pItmOut );
ulMax = ulOff + (DK_FACSIZE * DK_BUFSIZE);
cOut = (char *)hb_xgrab( ulMax );
memcpy( cOut, hb_itemGetCPtr( pItmOut ), ulOff );
for(;;){
GetExitCodeProcess( pi.hProcess, &ulRes );
if( ulRes != STILL_ACTIVE ) break;
PeekNamedPipe( hRPipe, NULL, 0, NULL, &ulBytes, NULL );
if( ulBytes > 0 ){
ReadFile( hRPipe, cBuffer, DK_BUFSIZE, &ulRead, NULL );
if( ulOff + ulRead > ulMax ){
ulMax += DK_FACSIZE * DK_BUFSIZE;
cOut = (char *)hb_xrealloc( cOut, ulMax );
}
memcpy( cOut + ulOff, cBuffer, ulRead );
ulOff += ulRead;
}
Sleep( 10 );
}
do{
PeekNamedPipe( hRPipe, NULL, 0, NULL, &ulBytes, NULL );
if( ulBytes > 0 ){
ReadFile( hRPipe, cBuffer, DK_BUFSIZE, &ulRead, NULL );
if( ulOff + ulRead > ulMax ){
ulMax += DK_FACSIZE * DK_BUFSIZE;
cOut = (char *)hb_xrealloc( cOut, ulMax );
}
memcpy( cOut + ulOff, cBuffer, ulRead );
ulOff += ulRead;
}
}while( ulBytes > 0 );
CloseHandle( hRPipe ); CloseHandle( hWPipe );
hb_itemPutCL( pItmOut, cOut, ulOff );
hb_retnl( ulRes );
hb_xfree( cOut );
}
}
/
*******************************************************************************
* FILTER OUTPUT CONSOLA PROCESSING \r & \n
* ----------------------------------------
* FilterOutCon( @cOut )
*******************************************************************************/
HB_FUNC( FILTEROUTCON )
{
PHB_ITEM pItmOut = hb_param( 1, HB_IT_STRING );
if( !pItmOut || !ISBYREF( 1 ) ){
hb_errRT_BASE_SubstR( EG_ARG, 3012, NULL, "FILTEROUTCON", 1,
hb_paramError(1) );
}else{
char *cRes, *cOut = hb_itemGetCPtr( pItmOut );
ULONG n, i, k, ulLen = hb_itemGetCLen( pItmOut );
if( ulLen > 0 ){
cRes = (char *)hb_xgrab( ulLen );
for( n = i = k = 0; i < ulLen; i++ ){
if( cOut[i] == '\r' && cOut[i+1] != '\n') k = n;
else cRes[k++] = cOut[i];
if( cOut[i] == '\n' ) n = k;
}
hb_itemPutCL( pItmOut, cRes, k );
hb_xfree( cRes );
}
}
}
/* END */
_______________________________________________
Harbour mailing list
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour