AppleScript and shell script issue

I used to run a shell command with AppleScript for authentication to a radius server, this was running fine as I could specify a parameter for the password.

the shell process was updated and don't accept the password parameter anymore and have to be done separately (prompted by terminal), so in terminal its look like it

~mycommand authenticate -username 
~password

unless I'm wrong "do shell script"m run in different instance so it's no point doing

do shell script + auth command
do shell script + password

is they anyway I can still use AppleScript and somehow let AppleScript answer with the password?


The following example AppleScript code shows an example of how it could be coded for iTerm2.

set myPassword to text returned of ¬
    (display dialog "Enter Password:" default answer "" with hidden answer)

tell application "iTerm"
    set myWindow to (create window with default profile)
    tell myWindow to tell the current session
        write text "echo mycommand authenticate -username"
        delay 1
        write text "echo " & myPassword
        delay 1
    end tell
    close myWindow
end tell

Notes:

As coded, it uses echo just for testing purposes, obviously you'd remove echo and "echo " & for production run.

The delay commands may need to be adjusted, or may not be necessary at all. Test with the actual commands to see.