如何使用命令行参数在后续提示中提供输入(批处理文件)
我正在使用批处理文件在我的应用程序中运行某些操作。我使用的命令不将密码作为参数,而是在运行时提示输入密码。这会阻碍该脚本的自动化。我想知道如何将密码作为参数并在应用程序提示时提供给应用程序。
I am using batch file to run certain operation in my application. The command I am using does not take password as a parameter instead it prompts for it while running. This is coming in the way of automating this script. I would like to know how I can take password as a parameter and provide to the application when it prompts.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参考您对 Johannes 的回答,您需要将对
pg_dump
的调用修改为如下所示:echo %3|pg_dump -h %1 -U %2 %4 > %5
问题是 pg_dump 不允许您通过 stdin 传递密码。这意味着该解决方案在这里不起作用。
但正如您可以在文档此处和此处,有一种(不安全)提供密码的方法环境变量
PGPASSWORD
。因此,只需像这样修改您的批处理文件:
Reffering to you comment to Johannes' answer, you would need to modify your call to
pg_dump
to something like this:echo %3|pg_dump -h %1 -U %2 %4 > %5
The Problem is that pg_dump doesn't allow you to pass in the password via stdin. That means this solution will not work here.
But as you can read in the docs here and here, there is the (unsecure) way of providing the password via environment variable
PGPASSWORD
.So simply modify your batch file like this: