【发布时间】:2012-08-30 18:08:49
【问题描述】:
我有一个windows exe,它显示一些版权信息,连接到服务器,然后提示输入用户名和密码。
所以每当我运行它时,我都必须等待提示输入用户名和密码。 我一般在命令开始显示版权信息后先输入用户名、密码,但这是一种粗略的方式。
有没有更好的方法在批处理文件中将参数传递给 windows 命令的输入提示符,这样我就可以避免总是输入它们?
附:在 Linux 中,我们使用
linux_command <<delimiter
inputparamvalue1
inputparamvalue2
delimiter
linux_command 将运行并在第一个输入提示时读取 inputparamvalue1,在下一个输入提示时读取 inputparamvalue2
作为对 James 的回应,感谢您提供有关安全性的建议。我会处理的。
我尝试实施您的解决方案,但没有奏效。
这些是我的文件。请看看你是否得到任何提示。
vpn.bat
@ echo off
"C:\Program Files (x86)\Cisco\Cisco AnyConnect VPN Client\vpncli.exe" connect "mycompanyvpnsite.com"
login.txt
myusername
mypassword
startvpn.bat
@ECHO OFF
CALL vpn.bat < login.txt
ECHO I'm back!
结果
D:\>startvpn.bat
Cisco AnyConnect VPN Client (version 2.5.6005) .
Copyright (c) 2004 - 2010 Cisco Systems, Inc.
All Rights Reserved.
>> state: Disconnected
>> notice: Ready to connect.
>> registered with local VPN subsystem.
>> state: Disconnected
>> notice: Ready to connect.
VPN> >> contacting host (mycompanyvpnsite.com) for login information...
>> notice: Contacting mycompanyvpnsite.com.
VPN>
>> Please enter your username and password.
Username: [myusername] Password:
它显示的用户名 myusername 是从我以前的手动登录中缓存的。因此,这次运行似乎没有从 login.txt 中获取任何值。
如果我在没有任何参数的情况下单独执行了我的 vpn.bat,我会得到这样的提示
VPN>
>> Please enter your username and password.
Username: [myusername] <i press enter to take the cached value>
Password: ******** <i enter password and press enter>
它连接起来。
vpn 客户端没有权限在命令行上指定密码,这就是我尝试这种方式的原因。
【问题讨论】:
-
试试这个:(echo inputparamvalue1 & echo inputparamvalue2) |命令
-
@HarryJohnston,您的解决方案给出的结果与詹姆斯的相同。
-
这已在stackoverflow.com/a/28048413/397331 中解决,使用:
vpncli.exe -s (...)
标签: windows command-line batch-file