AppleScript and shell script issue
The following example AppleScript code shows an example of how it could be coded for iTerm2.
set myPassword to text returned of ¬
    (display dialog &quot;Enter Password:&quot; default answer &quot;&quot; with hidden answer)

tell application &quot;iTerm&quot;
    set myWindow to (create window with default profile)
    tell myWindow to tell the current session
        write text &quot;echo mycommand authenticate -username&quot;
        delay 1
        write text &quot;echo &quot; &amp; 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 &quot;echo &quot; &amp;  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.