Automation 如何切换Tcl interact和telnet自动化?

Automation 如何切换Tcl interact和telnet自动化?,automation,tcl,expect,telnet,mud,Automation,Tcl,Expect,Telnet,Mud,与autoexpect类似但不同的是,autoexpect将始终为任何给定输入生成相同的输出。然而,至少有时会尝试允许用户输入 其工作原理是将控制权传递回用户,如下所示: thufir@dur:~/NetBeansProjects/spawnTelnet/telnet$ thufir@dur:~/NetBeansProjects/spawnTelnet/telnet$ tclsh main.tcl got nyc spawn telnet rainmaker.wunderground.com

与autoexpect类似但不同的是,autoexpect将始终为任何给定输入生成相同的输出。然而,至少有时会尝试允许用户输入

其工作原理是将控制权传递回用户,如下所示:

thufir@dur:~/NetBeansProjects/spawnTelnet/telnet$ 
thufir@dur:~/NetBeansProjects/spawnTelnet/telnet$ tclsh main.tcl 
got nyc
spawn telnet rainmaker.wunderground.com
Trying 35.160.169.47...
Connected to rainmaker.wunderground.com.
Escape character is '^]'.
------------------------------------------------------------------------------
*               Welcome to THE WEATHER UNDERGROUND telnet service!            *
------------------------------------------------------------------------------
*                                                                            *
*   National Weather Service information provided by Alden Electronics, Inc. *
*    and updated each minute as reports come in over our data feed.          *
*                                                                            *
*   **Note: If you cannot get past this opening screen, you must use a       *
*   different version of the "telnet" program--some of the ones for IBM      *
*   compatible PC's have a bug that prevents proper connection.              *
*                                                                            *
*           comments: jmasters@wunderground.com                              *
------------------------------------------------------------------------------

Press Return to continue:

Press Return for menu
or enter 3 letter forecast city code-- nyc
Weather Conditions at 02:51 AM EDT on 08 May 2020 for New York JFK, NY.
Temp(F)    Humidity(%)    Wind(mph)    Pressure(in)    Weather
========================================================================
  54          55%         NW at 16       29.83      Mostly Cloudy

Forecast for New York, NY
327 am EDT Fri may 8 2020

.Today...Cloudy. A slight chance of rain this morning, then rain
this afternoon. Highs in the upper 50s. Northwest winds around
5 mph, becoming south this afternoon. Chance of rain 80 percent. 
.Tonight...Rain in the evening, then rain likely with a slight
chance of snow after midnight. Cold with lows in the upper 30s.
East winds 5 to 10 mph with gusts up to 20 mph, increasing to
northwest 15 to 20 mph with gusts up to 30 mph after midnight.
Chance of precipitation 90 percent. 
.Saturday...Partly sunny. A slight chance of showers in the
afternoon. Windy with highs around 50. Northwest winds 20 to
30 mph with gusts up to 40 mph. Chance of rain 20 percent. 
.Saturday night...Partly cloudy with a slight chance of showers
in the evening, then mostly clear after midnight. Breezy with
lows in the upper 30s. West winds 15 to 25 mph with gusts up to
40 mph. Chance of rain 20 percent. 
   Press Return to continue, M to return to menu, X to exit: x
Connection closed by foreign host.
thufir@dur:~/NetBeansProjects/spawnTelnet/telnet$ 
main.tcl运行的代码:

当使用上面的程序时,我会投入更多,我如何切换交互开/关,或者更好地混合交互与非交互

也许是拖延或者什么都不做或者什么都不做

因此,只有当expect没有找到任何东西时,才能传递到interact,然后以某种方式重新启用expect…?

interact可以采取与expect类似的模式和操作。特别是,您可以使用操作return离开interact并继续执行以下语句。要匹配的一个有用模式是control-D,它通常用于表示文件结束。乙二醇

interact \004 return

如果在八进制中看到控制D,ASCII码4,则继续下一个语句。也有预期的基础。为一个非平凡的服务设计一个好的交互模式可以是相当多的工作,仅仅是因为有很多要考虑的。这个主题在Don Libes的探索期望书中被很好地涵盖。我强烈建议你找一份并仔细阅读。

interact \004 return