Viktor Szakáts napsal(a):
Thanks Davor.

Here's a slightly tweaked version:
Great
Note, that I don't make a much tests, but seem to work as expected, only I have no idea what function return in nErrorLevel. In case that all is ok, expected behavior is that 0 be returned, but function return -2 in example. Maybe some tweaking is needed with returned values

best regards
Davor

---
#include "common.ch <http://common.ch>"
#include "fileio.ch <http://fileio.ch>"

FUNCTION hb_processRun( cCommand, cStdIn, cStdOut, cStdErr )

   LOCAL hProcess
   LOCAL hStdIn, hStdOut, hStdErr
   LOCAL nErrorLevel

   hProcess := hb_processOpen( cCommand, @hStdIn, @hStdOut, @hStdErr )
   IF hProcess == F_ERROR
      nErrorLevel := F_ERROR
   ELSE
      IF ISCHARACTER( cStdIn ) .AND. Len( cStdIn ) > 0
         FWrite( hStdIn, cStdIn )
      ENDIF
      IF PCount() >= 3
         cStdOut := ReadHnd( hStdOut )
      ENDIF
      IF PCount() >= 4
         cStdErr := ReadHnd( hStdErr )
      ENDIF
      nErrorLevel := hb_processValue( hProcess )
      hb_processClose( hProcess, .T. )
      FClose( hStdIn )
      FClose( hStdOut )
      FClose( hStdErr )
   ENDIF

   RETURN nErrorLevel

STATIC FUNCTION ReadHnd( hHandle )

   LOCAL cBuffer := Space( 4096 )
   LOCAL cOutput := ""
   LOCAL nLen

   DO WHILE ( nLen := FRead( hHandle, @cBuffer, Len( cBuffer ) ) ) > 0
      cOutPut += SubStr( cBuffer, 1, nLen )
   ENDDO

   RETURN cOutput
---

Any opinions on including it in core RTL? Przemek?

Brgds,
Viktor

2009/6/16 Davor Siklic <s...@msoft.cz <mailto:s...@msoft.cz>>

    Hi all

    I need to have run command with standard input,  std. output and
    error output which I  use in past. After discover found
    hb_process* functions and find that are little difficult to use.
    Attached is syscmd.prg and is good example of using hb_process*
    functions. I get inspired with uhttpd. Be free to use or include
    this in harbour if find useful

    best regards
    Davor


------------------------------------------------------------------------

_______________________________________________
Harbour mailing list
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour

_______________________________________________
Harbour mailing list
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to