Archive: Answering to "Password:" prompt in console


Answering to "Password:" prompt in console
Hello,
I am trying to import a dump in PostgreSQL. For that i am using:

C:\>ExecWait "C:\Program Files\PostgreSQL\8.0.0-beta5\bin\psql -U postgres MyDB -f D:\dumps\db.dmp -p 5433"

Then it shows password prompt, which i am trying to handle with:

C:\>FindWindow $R0 windowtitle "C:\Program Files\PostgreSQL\8.0.0-beta5\bin\psql.exe"

And sending the pass to the console:

C:\>SendMessage $R0 ${WM_COMMAND} "STR:postgres" 0

Everything is in command line, without any GUI.
I tried also to pass the password in first command, but it appears extra parameter, and ignores it or some of the other.
Thanks for any help.


Isn't there a command-line switch for the password?

-Stu


For console apps ExecDos may help if your program not require terminal emulation.


Thnk you, Takhir,
it seems ExecDos can do the job, but i guess i don't do something wright, becouse the result is the same: showing a console with "Password: _" . This is my line, if you see something wrong:

ExecDos::exec /NOUNLOAD /ASYNC "/BRAND=Executing console application" /TIMEOUT=5000 "C:\Program Files\PostgreSQL\8.0.0-beta5\bin\psql.exe" "postgres"


ExecDos::exec "/BRAND=Executing console application" /TIMEOUT=5000 "C:\Program Files\PostgreSQL\8.0.0-beta5\bin\psql.exe" "postgres$\n"

is better ( \n at the end of password and simple sync execution for test), but if ExecDos not hides psql.exe console window (end you can see console output "Password:") this may be a problem.. We already had problems with MySQL utilities :(

Nope. The same.


Actually i think the problem is another - i can't handle the console window. It is ok with the Installer window, or the NSIS Compilator window, but not with console. The title is:

C:\Program Files\PostgreSQL\8.0.0-beta5\bin\psql.exe

If I change the .exe file it still doesn't work.
What could be a problem...?


Hello

to do that with Telnet I do this:

ExecShell "" "telnet" "-f temp.txt $CataIP" SW_HIDE

FindWindow $R0 "" "Telnet $CataIP"

;Send password
Push $R0
Push "$Password"
Call SendChars

;send Enter Key
SendMessage $R0 ${WM_CHAR} 13 0


with


; SendChars:
; Send a stream of WM_CHAR messages to a window to simulate user input
; Usage:
; Push <window-handle>
; Push <message>
; Call SendChars

Function SendChars
Exch $R0 ; Get string
Exch
Exch $R1 ; Get hwnd
Push $R2
Push $R3
StrCpy $R2 0 ; Char index
loop:
StrCpy $R3 $R0 1 $R2 ; Get next char
StrCmp $R3 "" done
Push $R3
Call CharToAscii ; Convert it to ASCII
Pop $R3
SendMessage $R1 258 $R3 0 ; Send a WM_CHAR message
IntOp $R2 $R2 + 1
Goto loop
done:
Pop $R3
Pop $R2
Pop $R1
Pop $R0
FunctionEnd

; CharToAscii:
; Convert a character to it's ascii code
; Usage:
; Push <character>
; Call CharToAscii
; Pop <ascii-code>

Function CharToAscii
Exch $R0 ; Get character
Push $R1
Push $R2
StrCpy $R1 255 ; ASCII code test counter
loop:
IntFmt $R2 "%c" $R1 ; Convert current test counter to it's char
StrCmp $R2 $R0 done ; Have we found it yet? (note - not case sensitive)
IntOp $R1 $R1 - 1 ; Next code
IntCmp $R1 0 "" "" loop
done:
Pop $R2
Exch
Pop $R0
Exch $R1
FunctionEnd


Best Regards