[Gambas-user] Writing (or Printing) data to a process

easuter easuter at ...626...
Tue May 1 12:50:49 CEST 2007




Werner-9 wrote:
> 
> 
> I have done something similar recently to control the Videolan video
> player/transcoder/streamer. Here is a code snippet:
> '----------------------------------------------
> 
> PRIVATE $vlc AS Process 'note: this is a global variable
> 
> 
> PUBLIC SUB Form_Open()
> ...
>  $vlc = EXEC ["vlc", "-I", "rc", "--video-x=0", "--video-y=0"] FOR INPUT
> OUTPUT AS "$vlc"
> ...
> END
> 
> 
> PUBLIC SUB $vlc_Read() 'reading from the $vlc process
>   DIM s AS String
>   DIM sa AS String[]
>  
>   WHILE Lof($vlc) > 0
>     READ #$vlc, s, Lof($vlc)
>     s = Replace$(s, "\r", "") 'kick out carriage returns
>     sa = Split(s, "\n")
>     FOR EACH s IN sa
>       PRINT s
>     NEXT
>   WEND
> END
> 
> '-------------------------------------
> 
> Example: if I want to send a command to the application I just do
> 
> PRINT #$vlc,"playlist"
> 
> and $vlc_Read will receive the playlist.
> 
> Regards
> Werner
> 
> 


Thanks so much!
I made a few small changes and it worked perfectly :D

FWIW, I'm attempting to write a simple frontend to "su" and so far it seems
to be working ok.
I have the subroutines that do all the "dirty work" in a separate module and
the form opening executes the command, and the ok button writes out the
password.
It still needs work, but the basics are in place:

http://clientes.netvisao.pt/alynnsut/VSu.png

snip:
--------------------------------------------------

PUBLIC SUB RunCmd()
  
  $hSu = EXEC ["su", "-c", sCommand] FOR INPUT OUTPUT AS "$hSu"
  
END

PUBLIC SUB $hSu_Read()
  
  DIM sInputString AS String
  
  WHILE NOT Eof($hSu)
    READ #$hSu, sInputString, Lof($hSu)
  WEND 
  'PRINT sInputString
    
END

-----------------------
PUBLIC SUB OkBtn_Click()

  PRINT #MGlobal.$hSu, PwTxtBox.Text

END
--------------------------


I will mention you in the AUTHORS notice ;)
Thanks again for your help!
-- 
View this message in context: http://www.nabble.com/Writing-%28or-Printing%29-data-to-a-process-tf3672829.html#a10267346
Sent from the gambas-user mailing list archive at Nabble.com.





More information about the User mailing list