【问题标题】:using "ask dialog" command to immediately pass text through Bash command使用“询问对话框”命令立即通过 Bash 命令传递文本
【发布时间】:2020-12-09 01:47:48
【问题描述】:

我想使用“询问对话”命令立即传递问题。我正在尝试自动化启动终端和运行“询问对话框”的过程。每当我的 bash 脚本运行时,它会在 Alexa 实例打开后暂停。

#!/bin/bash/
cd /Users/AlexaDirectory/
ask dialog 
#this is where I need to ask Alexa a question automatically. 
#I have tried running "ask dialog && (insert question)", but the script pauses once it reaches "ask dialog"
echo "end"

这是我在运行 .sh 时通常看到的内容

MacBook-Pro Desktop % bash Test.command
Defaulting locale to the first value from the skill manifest: en-US

======================================= Welcome to ASK Dialog =======================================
=========== In interactive mode, type your utterance text onto the console and hit enter ============
===================== Alexa will then evaluate your input and give a response! ======================
=== Use ".record <fileName>" or ".record <fileName> --append-quit" to save list of utterances to a file. ===
=============== You can exit the interactive mode by entering ".quit" or "ctrl + c". ================

User  > 

如果不能立即传递问题,是否可以向终端发送击键?

【问题讨论】:

  • 你想要expect(一种建立在TCL之上的脚本语言,专门用于自动化其他程序,读取它们的输出并写入它们的输入) ) - 尽管这与您的标题所要求的完全相反。尽管您可能想要一个heredoc,以便能够将文本写入ask 的标准输入?很不清楚你真正想要什么,所以不清楚如何回答。
  • ...当您说“通过 bash 命令传递文本”时——具体来说,应该通过 which bash 命令传递 which 文本?
  • 备份:当您说“通过一个问题”时,您是否希望将您的问题写入ask 命令? (如果是这样,你想要的可能是一个heredoc:ask &lt;&lt;EOF,然后是你的问题文本,然后是EOF)。
  • 太棒了——听起来像heredoc真的是你想要的,那么;我们确实有几个问答条目描述了如何做到这一点。
  • 查看How do I provide input to a C program from bash? 的答案——请注意,虽然这个问题涉及到很多 C 特定的细节,但答案非常笼统。

标签: bash shell command-line terminal ask-cli


【解决方案1】:

在 Charles Duffy 的帮助下,使用herestring 就是答案。

当调用ask dialog 时进程冻结,并且修复正在发送ask dialog &lt;&lt;&lt; "question for alexa placed here"。这也会立即结束 Alexa 实例。

【讨论】:

    【解决方案2】:

    您可以尝试使用the expect command。我一直在努力解决类似的问题。在非交互模式下运行ask init。最后我是这样解决的。

    echo '#!/usr/bin/expect 
    spawn ask init 
    expect "? Skill Id (leave empty to create one):" 
    send "my-skill\r" 
    expect "? Skill package path:" 
    send "./path/to/skill-package\r" 
    expect "? Lambda code path for default region (leave empty to not deploy Lambda):" 
    send "./path/to/lampda-package\r"
    ' > ask_init.sh
    chmod u+x ask_init.sh 
    ./ask_init.sh
    

    仅供参考,我还尝试过使用|echo 的组合来传递答案,如下所示:

    echo 'quantum-skill
    ./path/to/skill-package
    ./path/to/lampda-package
    ' | ask init
    

    printf,像这样:

    printf 'quantum-skill\n./path/to/skill-package\n./path/to/lambda-package\n' | ask init
    

    后者都不起作用。所以我建议改用expect

    【讨论】:

      猜你喜欢
      • 2016-09-05
      • 2014-10-17
      • 1970-01-01
      • 2014-11-05
      • 2016-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多