代码之家  ›  专栏  ›  技术社区  ›  Thufir

如何使用线程和tee记录来自服务器的telnet响应?

  •  2
  • Thufir  · 技术社区  · 4 年前

    不同的telnet客户机之间有区别,当然这些客户机与Apache库之间也有区别。在这种情况下,是的,使用一个实际的telnet客户机来进行MUD,其中的服务器可能非常finnicky,所以API或socket就不能工作了。


    我该怎么做 go 关于:

    创建读取 一个命令的输出并将其写入下一个命令的输入 命令。

    output 用于:

    package mud;
    
    import java.io.IOException;
    import java.util.Arrays;
    import java.util.List;
    import java.util.logging.Logger;
    
    public class App {
    
        private final static Logger log = Logger.getLogger(App.class.getName());
    
        private void telnet() throws IOException {
            String s = "rainmaker.wunderground.com";
    
            List<String> telnetCommand = Arrays.asList("sh", "-c", "rainmaker.wunderground.com | tee -a -i telnet.log");
            String foo = "foo";
    
            ProcessBuilder pb = new ProcessBuilder(telnetCommand);
            Process p = pb.start();
        }
    
        public static void main(String[] args) throws IOException {
            new App().telnet();
        }
    
    }
    

    因此,首先我需要捕获结果(日志文件):

    thufir@dur:~/NetBeansProjects/mud$ 
    thufir@dur:~/NetBeansProjects/mud$ ll
    total 96
    drwxrwxr-x 7 thufir thufir  4096 May  3 21:00 ./
    drwxrwxr-x 3 thufir thufir  4096 May  3 19:24 ../
    drwxrwxr-x 5 thufir thufir  4096 May  3 20:50 build/
    -rw-rw-r-- 1 thufir thufir  1034 May  3 19:20 build.gradle
    drwxrwxr-x 8 thufir thufir  4096 May  3 21:00 .git/
    -rw-rw-r-- 1 thufir thufir   154 May  3 19:20 .gitattributes
    -rw-rw-r-- 1 thufir thufir   382 May  3 19:20 .gitignore
    drwxrwxr-x 8 thufir thufir  4096 May  3 19:24 .gradle/
    drwxrwxr-x 3 thufir thufir  4096 May  3 19:20 gradle/
    -rwxrwxr-x 1 thufir thufir  5764 May  3 19:20 gradlew*
    -rw-rw-r-- 1 thufir thufir  3056 May  3 19:20 gradlew.bat
    -rw-rw-r-- 1 thufir thufir 35149 May  3 19:20 LICENSE
    -rw-rw-r-- 1 thufir thufir    34 May  3 19:20 README.md
    -rw-rw-r-- 1 thufir thufir   350 May  3 19:20 settings.gradle
    drwxrwxr-x 4 thufir thufir  4096 May  3 19:44 src/
    thufir@dur:~/NetBeansProjects/mud$ 
    thufir@dur:~/NetBeansProjects/mud$ gradle clean run
                                                                                                            
    BUILD SUCCESSFUL in 948ms
    3 actionable tasks: 3 executed
    thufir@dur:~/NetBeansProjects/mud$                                                                      
    thufir@dur:~/NetBeansProjects/mud$ ll                                                                   
    total 96
    drwxrwxr-x 7 thufir thufir  4096 May  3 21:00 ./
    drwxrwxr-x 3 thufir thufir  4096 May  3 19:24 ../
    drwxrwxr-x 5 thufir thufir  4096 May  3 21:00 build/
    -rw-rw-r-- 1 thufir thufir  1034 May  3 19:20 build.gradle
    drwxrwxr-x 8 thufir thufir  4096 May  3 21:00 .git/
    -rw-rw-r-- 1 thufir thufir   154 May  3 19:20 .gitattributes
    -rw-rw-r-- 1 thufir thufir   382 May  3 19:20 .gitignore
    drwxrwxr-x 8 thufir thufir  4096 May  3 19:24 .gradle/
    drwxrwxr-x 3 thufir thufir  4096 May  3 19:20 gradle/
    -rwxrwxr-x 1 thufir thufir  5764 May  3 19:20 gradlew*
    -rw-rw-r-- 1 thufir thufir  3056 May  3 19:20 gradlew.bat
    -rw-rw-r-- 1 thufir thufir 35149 May  3 19:20 LICENSE
    -rw-rw-r-- 1 thufir thufir    34 May  3 19:20 README.md
    -rw-rw-r-- 1 thufir thufir   350 May  3 19:20 settings.gradle
    drwxrwxr-x 4 thufir thufir  4096 May  3 19:44 src/
    -rw-rw-r-- 1 thufir thufir     0 May  3 21:00 telnet.log
    thufir@dur:~/NetBeansProjects/mud$ 
    thufir@dur:~/NetBeansProjects/mud$ cat telnet.log 
    thufir@dur:~/NetBeansProjects/mud$ 
    

    thufir@dur:~$ 
    thufir@dur:~$ telnet rainmaker.wunderground.com | tee -a -i telnet.log
    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-- 
    
                     WEATHER UNDERGROUND MAIN MENU
                    ******************************
                     1) U.S. forecasts and climate data
                     2) Canadian forecasts
                     3) Current weather observations
                     4) Ski conditions
                     5) Long-range forecasts
                     6) Latest earthquake reports
                     7) Severe weather
                     8) Hurricane advisories
                     9) Weather summary for the past month
                    10) International data
                    11) Marine forecasts and observations
                    12) Ultraviolet light forecast
                     X) Exit program
                     C) Change scrolling to screen
                     H) Help and information for new users
                     ?) Answers to all your questions
                       Selection:x
    Connection closed by foreign host.
    thufir@dur:~$ 
    thufir@dur:~$ cat telnet.log 
    Trying 127.0.0.1...
    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-- 
                     WEATHER UNDERGROUND MAIN MENU
                    ******************************
                     1) U.S. forecasts and climate data
                     2) Canadian forecasts
                     3) Current weather observations
                     4) Ski conditions
                     5) Long-range forecasts
                     6) Latest earthquake reports
                     7) Severe weather
                     8) Hurricane advisories
                     9) Weather summary for the past month
                    10) International data
                    11) Marine forecasts and observations
                    12) Ultraviolet light forecast
                     X) Exit program
                     C) Change scrolling to screen
                     H) Help and information for new users
                     ?) Answers to all your questions
                       Selection:thufir@dur:~$ 
    thufir@dur:~$ 
    

    delay 在等待回应时 相当地 而不是仅仅运行命令然后退出?

    0 回复  |  直到 4 年前