Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Feeding input to an interactive command line application

I'd like to feed inputs to a command line interface for Cisco AnyConnect vpncli.exe (v2.3) to automate its (re)connection. It does not take username nor password as command line arguments, but reads those interactively from the user via the command line interface.

Problem is that piping input to vpncli.exe doesn't seem to work for the password. It works for everything except the password. So doing things like this doesn't work:

vpncli.exe < input.txt
type input.txt | vpncli.exe

The application just gets stuck at where it asks for the password.


Below is an example of normal (working) execution where the user enters the parameters:

Example vpncli.exe run

Notice how the password characters get transformed to *.


Using tools like AutoIt or AutoHotKey to send the inputs to a command prompt window works, but is clumsy and fragile (does not work if the tool can't get to the command prompt window for some reason).


Is there any way to send inputs to such interactive CLI application using PowerShell?

(Or using any other scripting language or some other means?)

like image 324
Qtax Avatar asked Jul 14 '12 00:07

Qtax


People also ask

What is interactive command line?

In interactive mode, you enter the command without options, and you are prompted for responses. In direct mode, you enter the full command, including options, and prompts are not provided.

How do I run a shell script in interactive mode?

You run the shell script (pure. bat on Windows and pure on Linux®) from the pure. cli/bin directory on your local computer. In this procedure you start in interactive mode, specifying the host name or IP address for the system, along with an authorized user ID and password to start a user session.


1 Answers

you need to create an usual text file like

connect myvpnhost
myloginname
mypassword

save it as myfile.dat (for example) and then call

"%ProgramFiles%\Cisco\Cisco AnyConnect Secure Mobility Client\vpncli.exe" -s < myfile.dat

like image 89
George Hazan Avatar answered Sep 20 '22 05:09

George Hazan