views:

215

answers:

1

Is it possible to create an interactive cmd under Windows?

I am looking for a scripting solution to login to a server remotely which prompts password entering.

Take SSH as an example. A normal user will do the following at a command line window:

C:>ssh2 [email protected] "echo Hello"
user's password: ********
Hello

The second line, which prompts password entering, must be manually entered by a user. Stdin redirection does not work, for example,

ssh2 [email protected] "echo Hello" < password.txt  # not working

Therefore, I am looking for a script, which can impersonate a user. In Linux we can use expect, for example:

#!/usr/bin/expect

spawn ssh [email protected] "ls"
expect *assword:
send "password\r"

I am looking for similar stuffs in Windows environment.

Update: If PowerShell can do the same, can someone paste a sample script? Thanks.

A: 

This problem is solved.

Use a powershell that creates a Process object and play with that object.

SiLent SoNG