向运行的程序发送参数,这些程序会自动期待用户输入 [英] sending arguments to running programs that expect user input automatically

查看:28
本文介绍了向运行的程序发送参数,这些程序会自动期待用户输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试自动执行备份脚本,但我使用的云备份提供商的 CLI 工具优化不佳.
第一次启动时,预计会运行,然后从stdin获取用户输入.
例子:

I am trying to automate a backup script, but the cloud-backup provider that I am using has a poorly optimized CLI tool.
When starting for the first time, it is expected to run and then get user input from stdin.
example:

c:/backup> jotta.exe login
accept licence (y/n):

然后:

enter token:

最好的解决方案是,如果原始开发人员在运行程序时将这些作为参数/标志访问,但不幸的是,事实并非如此.

The best solution would have been if the original developers had made these accessible as arguments/flags when running the program, but unfortunately that is not the case.

有什么办法可以通过下一个输入"吗?到程序或使用 PowerShell 的程序参数队列?

Is there any way I can pass "the next input" to the program or a queue of arguments to the program with PowerShell?

推荐答案

您可以尝试逐行管道到 jotta.exestdin.这要求程序实际从 stdin 读取,而不是直接从键盘读取,在这种情况下 this answer 适用.

You can try to pipe to stdin of jotta.exe, line by line. This requires that the program actually reads from stdin as opposed to reading from the keyboard directly, in which case this answer applies.

'y', 'thetoken' | .\jotta.exe login

这里我们将一个字符串数组传送到 当前目录(由 .\ 表示).数组的每个元素都是一行输入,将排队等待应用程序从stdin读取.

Here we are piping an array of strings to jotta.exe in the current directory (denoted by .\). Each element of the array is one line of input, which will be queued until the application reads from stdin.

您也可以将两行作为一个字符串传递,嵌入换行符,例如.:

You could also pass both lines as one string, embedding the linefeed character, e. g.:

"y`nthetoken" | .\jotta.exe login

或者指定jotta.exe的完整路径:

'y', 'thetoken' | & 'C:\Program Files\JottaCLI\Jotta.exe' login

(我刚刚创建了这条路径,请根据需要更正.)

(I've just made this path up, correct it as needed.)

调用运算符 & 是必需的,因为我们使用了带引号的路径.有关详细信息,请参阅此答案.

The call operator & is required because we are using a quoted path. See this answer for details.

这篇关于向运行的程序发送参数,这些程序会自动期待用户输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆