[Gambas-user] Write to process in Gambas

Eugeny Gazzaev zz84.kh at ...626...
Fri Feb 18 23:15:23 CET 2011


Hello!

How I can write to console process some input data? I try to process
this code, but it not working. It run console program htpasswd, that
generate password file for Apache. If run htpasswd in console, it two
time ask the password:
---------------------------------------------------
zz84 at ...40...:~$ htpasswd -c ~/mypassword.txt zz84
New password: 
Re-type new password: 
Adding password for user zz84
---------------------------------------------------

Code beelow, and Im attach project file.

' Gambas module file

PUBLIC hProcess AS Process
PUBLIC password AS String = "mypassword"

PUBLIC SUB Main()

  DIM path AS String = User.Home &/ "htpasswd.txt"

  IF Exist(path) THEN
    hProcess = SHELL Subst$("htpasswd &1 myUser", path) FOR READ WRITE
AS "MyProcess"
  ELSE
    hProcess = SHELL Subst$("htpasswd -c &1 myUser", path) FOR READ
WRITE AS "MyProcess"
  END IF

END

PUBLIC SUB MyProcess_Read()

  DIM sLine AS String

  READ #hProcess, sLine, -256

  PRINT sLine

  IF (String.InStr(sLine, "New password:") > 0) OR (String.InStr(sLine,
"Re-type new password:") > 0) THEN
    PRINT #hProcess, password
  END IF

END
-------------- next part --------------
A non-text attachment was scrubbed...
Name: write-to-process.tar.bz2
Type: application/x-bzip-compressed-tar
Size: 8854 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20110219/90c3fb71/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: ??? ????? ????????? ????????? ???????? ????????
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20110219/90c3fb71/attachment.sig>


More information about the User mailing list