Jump to content

Howto Input Password Into Command Prompt


Recommended Posts

The following script opens a command prompt and requests a password as the result of the -W (compulsory) option

StdoutRead works fine for collecting the program output, but what technique(s) is available to talk to the command prompt and supply the password?

#include <Constants.au3>

Local $rslt = Run("psql.exe -Upostgres -W", @SystemDir, @SW_MAXIMIZE, $STDIN_CHILD + $STDOUT_CHILD)

Local $data

While True

$data_temp = StdoutRead($rslt)

$data = $data & $data_temp

If @error Then ExitLoop

Sleep(25)

WEnd

MsgBox(0, "PSQL Data", $data)

MsgBox(0, "Exit", $rslt)

Thanks

Paul Fraser

Link to comment
Share on other sites

The following script opens a command prompt and requests a password as the result of the -W (compulsory) option

StdoutRead works fine for collecting the program output, but what technique(s) is available to talk to the command prompt and supply the password?

#include <Constants.au3>

Local $rslt = Run("psql.exe -Upostgres -W", @SystemDir, @SW_MAXIMIZE, $STDIN_CHILD + $STDOUT_CHILD)

Local $data

While True

$data_temp = StdoutRead($rslt)

$data = $data & $data_temp

If @error Then ExitLoop

Sleep(25)

WEnd

MsgBox(0, "PSQL Data", $data)

MsgBox(0, "Exit", $rslt)

Thanks

Paul Fraser

There is no good way to write to the console command line (that I know of).

Try this:

$sPassword = "Pa$$word"
$sTemp = @TempDir & "\" & _TempFile(@TempDir)
FileWrite($sTemp, $sPassword & @CR)
Local $rslt = Run('psql.exe -Upostgres -W < "' & $sTemp & '"', @SystemDir, @SW_MAXIMIZE, $STDIN_CHILD + $STDOUT_CHILD)
FileDelete($sTemp)

Better would be if you can use ODBC/ADODB connection objects and avoid the console altogether, or use the equivalent of OSQL.exe's trusted connection (Windows authentication).

;)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

There is no good way to write to the console command line (that I know of).

Try this:

$sPassword = "Pa$$word"
$sTemp = @TempDir & "\" & _TempFile(@TempDir)
FileWrite($sTemp, $sPassword & @CR)
Local $rslt = Run('psql.exe -Upostgres -W < "' & $sTemp & '"', @SystemDir, @SW_MAXIMIZE, $STDIN_CHILD + $STDOUT_CHILD)
FileDelete($sTemp)

Better would be if you can use ODBC/ADODB connection objects and avoid the console altogether, or use the equivalent of OSQL.exe's trusted connection (Windows authentication).

;)

Hmmm...your "try this" did not work in my case and considering your comment about the console, it is time for a new approach, JDBC may be my next step.

Thanks for your efforts

Paul

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...