0

I want to use Python to execute this command in Windows 10 command-line:

"C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpncli.exe" connect [some_server]

and after that to automatically answer "y" on "Connect Anyway" prompt. Which is the best way to do that?

Thanks.

DCupovic
  • 1
  • 2
  • Does this answer your question? [How do I write to a Python subprocess' stdin?](https://stackoverflow.com/questions/8475290/how-do-i-write-to-a-python-subprocess-stdin) – mkrieger1 May 07 '20 at 13:04
  • If you clarify how you are calling that command in Python code, commenters might be able to help you more specifically. – Nils Guillermin May 08 '20 at 00:25
  • Hi @NilsGuillermin. Thank you for the suggestion. I just modified my question slightly. – DCupovic May 08 '20 at 09:11
  • @DCupovic I was thinking more along the lines of you posting the Python code you're using in your question. – Nils Guillermin May 10 '20 at 13:19
  • In any case, if the command you're running doesn't have an option to skip the prompt (sometimes that's a `-y` or a `--force`), you could try piping in an `ECHO 'yes'` by using a pipe, so it would look something like `ECHO "yes" | "C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpncli.exe" connect [some_server]` – Nils Guillermin May 10 '20 at 13:21

1 Answers1

0

This should run the exe file and send a "y" upon running it.

os.system('cmd /c' "echo y | C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpncli.exe")
Trooper Z
  • 1,617
  • 14
  • 31