使用管道空间的批处理文件提示

时间:2016-08-18 14:04:20

标签: windows batch-file cmd firebase

我使用firebase作为我的主机。当我上传我的网页时,我需要拨打两个cmd说明:

  1. firebase init
  2. firebase deploy
  3. 当我运行firebase init时,我必须回答一些问题。对于第一个问题,我输入y表示是,第二个我需要输入空格来取消选择一个项目,然后输入继续。

    我正在尝试使用批处理文件来执行此说明。

    我发现我可以在批处理文件中使用包含以下内容的管道,文件如下所示:

    echo y | firebase init
    

    但是这个"回应y"只是firebase init的第一条指令。之后我需要取消选择一个项目" space"而不是"输入"。

    我怎么写:

    (echo y
    echo "space"
    echo "enter") | firebase init
    

3 个答案:

答案 0 :(得分:1)

首先必须在右侧目录中使用echo创建firebase.json文件。这将取代firebase init命令。

然后运行:firebase deploy -P project别名。

在bash中它看起来像:

  

echo $'{       “数据库”:{       “规则”:“database.rules.json”       },       “托管”:{       “公众”:“公众”,       “重写”:[         {           “资源”: ”**”,           “目的地”:“/ index.html”         }       ]       }       } \ n'> firebase.json

     

firebase deploy -P Test_Google_Analytics

答案 1 :(得分:0)

尝试

(
 (echo(y) 
 (echo( )
 (echo()
) | firebase init

这通过管道发送

y<Linefeed>
<space><Linefeed>
<Linefeed>

括号似乎是不平衡的,但这是正确的,因为echo(确保内容将按原样打印。

答案 2 :(得分:0)

这对你有用吗?

@echo off

:: start command
firebase init

:: wait command to load. IP must be unreachable for -w to work as expected
ping 1.1.1.1 -n 1 -w 500 >NUL

call:sendKeys

exit/B

:: spawn a cscript to echo desired keys to the same cmd window
:: sleep time may need to be changed
:sendKeys
SetLocal 
set "_vbs_file_=%TEMP%\keys.vbs"
(
  echo(set oWS ^= CreateObject^("wScript.Shell"^)
  echo(wScript.Sleep 100
  echo(oWS.SendKeys "y"
  echo(wScript.Sleep 100
  echo(oWS.SendKeys " "
  echo(wScript.Sleep 100
  echo(oWS.SendKeys "{ENTER}"
)>"%_vbs_file_%"
if exist "%TEMP%\keys.vbs" (set "_spawn_=%TEMP%\keys.vbs") else (set "_spawn_=keys.vbs")
ping 1.1.1.1 -n 1 -w 50 >NUL
start /B /WAIT cmd /C "cls & "%_spawn_%" & del /F /Q "%_spawn_%" 2>NUL"
exit/B 0

编辑:当echo发送显式回车时,sendkeys可能是(也是ping延迟现在是1500毫秒)

@echo off

:: start command
firebase init

:: wait command to load. IP must be unreachable for -w to work as expected
ping 1.1.1.1 -n 1 -w 1500 >NUL

call:sendKeys

exit/B

:: spawn a cscript to echo desired keys to the same cmd window
:: sleep time may need to be changed
:sendKeys
SetLocal 
set "_vbs_file_=%TEMP%\keys.vbs"
(
  echo(set oWS ^= CreateObject^("wScript.Shell"^)
  echo(wScript.Sleep 100
  echo(oWS.SendKeys "y"
  echo(wScript.Sleep 100
  echo(oWS.SendKeys "{ENTER}"
  echo(oWS.SendKeys " "
  echo(wScript.Sleep 100
  echo(oWS.SendKeys "{ENTER}"
  echo(wScript.Sleep 100
  echo(oWS.SendKeys "{ENTER}"
)>"%_vbs_file_%"
if exist "%TEMP%\keys.vbs" (set "_spawn_=%TEMP%\keys.vbs") else (set "_spawn_=keys.vbs")
ping 1.1.1.1 -n 1 -w 50 >NUL
start /B /WAIT cmd /C "cls & "%_spawn_%" & del /F /Q "%_spawn_%" 2>NUL"
exit/B 0