hb_processRun Windows - how to hide / minimise the command box

459 views
Skip to first unread message

mithra...@gmail.com

unread,
Dec 8, 2017, 1:17:18 AM12/8/17
to Harbour Users
Hello

I am using hb_processRun() to run external commands.

sample code

eCode:= hb_processRun( "command with parameters", "", @outputtxt, @errtxt)

But the command box opens and closes up.

Can this be avoided? like hiding or minimising?

Thanks

Natarajan

Miroslav Georgiev

unread,
Dec 9, 2017, 2:52:33 AM12/9/17
to Harbour Users
Hi. I use hb_processRun(), and no window is opened (command box).

Please post a sample code with exact command

mithra...@gmail.com

unread,
Dec 9, 2017, 3:33:18 AM12/9/17
to Harbour Users
Hello Miroslav Georgiev

For example

Local eCode, opList, errList
eCode:= hb_processRun("c:\cygwin64\bin\bash.exe -l -c ls", "", @opList, @errList)

This code, when compiled as a text application - no issues.

But when compiled within gui application...there opens a text command box and closes off. Is there any way to avoid like hiding or minimised run, etc?

Please.

Natarajan

Miroslav Georgiev

unread,
Dec 9, 2017, 11:37:19 AM12/9/17
to Harbour Users
ok, can you try this
https://ritchielawrence.github.io/cmdow/

eCode:= hb_processRun("cmdow /run /hid c:\cygwin64\bin\bash.exe -l -c ls", "", @opList, @errList)

mithra...@gmail.com

unread,
Dec 9, 2017, 12:00:32 PM12/9/17
to Harbour Users
Hello Miroslav Georgiev

Oh. Great choice. Approaching in a different direction. But this adds a new executable and not every user would prefer such additional installations for running a software.

Forgetting cygwin...even a simple command called from GUI harbour would make the text command box jump out and jump in.

eCode:= hb_processRun("c:\windows\system32\xcopy.exe /?", "", @opList, @errList)

Marinas GUI has an execute command with hidden / minimised run. But the execute command itself is not a success.

Any other choices? possibilities? to have it run minimised?

Thanks

Natarajan

mithra...@gmail.com

unread,
Dec 9, 2017, 12:42:44 PM12/9/17
to Harbour Users
Hello Miroslav Georgiev

I also tried cmdow. It does not hide. And when I checked their web pages...

Some applications ignore this, use CMDOW to alter the window state after the application has started.

Feature to Run an external command minised is highly appreciated.

Natarajan

W.

unread,
Dec 9, 2017, 2:09:45 PM12/9/17
to Harbour Users
This is a windows specific-issue. If you have a GUI program and launch a console process, then it'll get it's own console window at start. If your app is console, then all console processes launched are intheriting yours.

Workaround? Compile GUI app as console or use winapi AllocConsole(). Then use a construct something like the following snippet, use HideConsole(). Console processes will then reuse your hidden window. HTH.

#ifdef __PLATFORM__WINDOWS

EXIT PROCEDURE WinConsoleExit()
   RestoreConsole()
   RETURN

#pragma BEGINDUMP 

#define HB_OS_WIN_32_USED 
#define _WIN32_WINNT 0x0400 

#include <windows.h> 
#include <wincon.h>
#include "hbapi.h" 
#include "hbapiitm.h" 

static HWND s_hWndHide = NULL;

HB_FUNC( HIDECONSOLE )
{
   typedef HWND ( WINAPI * P_GETCONSOLEWINDOW )( void );
   P_GETCONSOLEWINDOW pGetConsoleWindow;
   HMODULE hKernel32 = GetModuleHandle( TEXT( "kernel32.dll" ) );
   pGetConsoleWindow = ( P_GETCONSOLEWINDOW ) GetProcAddress( hKernel32, "GetConsoleWindow" );
   if( pGetConsoleWindow )
   {
      s_hWndHide = pGetConsoleWindow();
      ShowWindow( s_hWndHide, SW_HIDE );
   }
}

HB_FUNC( RESTORECONSOLE )
{
   if( s_hWndHide && IsWindow( s_hWndHide ) )
      ShowWindow( s_hWndHide, SW_RESTORE );
}

#pragma ENDDUMP

#endif

Mario H. Sabado

unread,
Dec 9, 2017, 11:22:13 PM12/9/17
to harbou...@googlegroups.com
Hi,

Have you tried leaving the 2nd parameter empty instead of ""?  Just a wild guess.

Regards,
Mario

--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-users+unsubscribe@googlegroups.com
Web: http://groups.google.com/group/harbour-users

---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

mithra...@gmail.com

unread,
Dec 10, 2017, 12:02:19 AM12/10/17
to Harbour Users
Hello Mhsabado

Not working. Even if command input is not defined and the command output is routed to a text file already, It just opens and closes up.

Also as Mr W. mentioned, creating the GUI application's own terminal window might help. I should give a try as per his given logic.

Thanks

Natarajan

Miroslav Georgiev

unread,
Dec 10, 2017, 1:44:45 PM12/10/17
to Harbour Users
Super. Post working example if it works, please

Robb

unread,
Dec 10, 2017, 11:24:16 PM12/10/17
to Harbour Users

I never figured out how to make hb_processRun() hide the window but I did learn how to get hb_processOpen() to do what I want. I've been using some variation of the below function for quite a while to run a silent shell and capture stdio (and stderr)

FUNCTION ShellExec( cCMD, lBackground, nLoopDelayMS )

   LOCAL nChild, nPID
   LOCAL hStdIn, hStdOUT
   LOCAL cOutResults
   LOCAL cStdOUT
   LOCAL nOutBytes
   LOCAL cResults := ""

   hb_default( @lBackground,  .T. )
   hb_default( @nLoopDelayMS, .200 )
   
   nChild := hb_processOpen( cCMD, @hStdIn, @hStdOut, @hStdOut, lBackground, @nPID )

   IF nChild >= 00
   
      cOutResults := ""

      cStdOut := Space( DEFAULT_BUFFER_SIZE )
      DO WHILE ! Empty( nOutBytes := FRead( hStdOut, @cStdOut, DEFAULT_BUFFER_SIZE ) )
         cOutResults += Left( cStdOut, nOutBytes )
         cStdOut     := Space( DEFAULT_BUFFER_SIZE )
         hb_idleSleep( nLoopDelayMS )
      ENDDO

      hb_processClose( nChild )
      #if defined( __PLATFORM__WINDOWS )
         hb_ProcessValue( nChild )
      #else
         hb_ProcessValue( nPID )
      #endif
      
   ELSE

      cResults := "<error>"

   ENDIF

   FClose( nChild  )
   FClose( hStdOUT )

   RETURN ( cResults )

Robb

Pritpal Bedi

unread,
Dec 11, 2017, 3:21:56 PM12/11/17
to Harbour Users
Hi Rob

Thanks for this function. I could fix a flaw in one of my 
applications modifying this function a bit. 


Pritpal Bedi 
a student of software analysis & concepts 

M., Ronaldo

unread,
Dec 11, 2017, 8:08:52 PM12/11/17
to Harbour Users
cURL := "https://groups.google.com/forum/#!topic/harbour-users/kXd56YMF91w"
wapi_ShellExecute( 0, 'open', cURL_, , , SW_SHOWMAXIMIZED ) // SW_SHOWMAXIMIZED = 3
Reply all
Reply to author
Forward
0 new messages