zoukankan      html  css  js  c++  java
  • 债务

    Expect 扩展允许 使用PTY与进程交互。

    你可以认为使用 expect:// wrapper 协议 来提供更简单更直观的文件系统功能。

    expect_popen

          通过Burne shell执行命令,并将PtY流打开到进程中。

    expect_expectl

          等待 进程 的输出,来匹配一个预期。要么指定时间到,要么已经有结束的标示(EOF)。

    如果提供匹配,则填充搜索结果。匹配的字符串可以在匹配[ 0 ]中找到。原始模式中的匹配子字符串(根据括号)可以在匹配[1]、匹配[2]等中找到,直到匹配[9](libexpect的限制) 

    <?php
    // Copies file from remote host:指定时间
    ini_set("expect.timeout", 30);


    $stream = fopen("expect://scp user@remotehost:/var/log/messages /home/user/messages.txt", "r");

    $cases = array( //预期项
        // array(pattern, value to return if pattern matched)
        array("password:", "asked for password"),
        array("yes/no)?",  "asked for yes/no")
    );

    while (true) {
        switch (expect_expectl($stream, $cases)) {
            case "asked for password":
                fwrite($stream, "my password ");
                break;
            case "asked for yes/no":
                fwrite($stream, "yes ");
                break;
            case EXP_TIMEOUT:
            case EXP_EOF:
                break 2; // break both the switch statement and the while loop   
            default:
                die "Error has occurred!";
        }
    }

    fclose($stream);
    ?>

  • 相关阅读:
    SQL 中文排序方式
    ASP.NET公有六种验证控件
    CustomValidator的使用方法
    c# 获取网页源码
    asp.net mvc 从客户端中检测到有潜在危险的 Request.Form 值的解决方法
    C#上传文件转字节流形式
    byte数组转换成文件保存到本地
    检测到有潜在危险的Request.Form值
    字节数组生成图片
    Edit Distance (编辑距离) .NET 实现
  • 原文地址:https://www.cnblogs.com/zhco/p/9572070.html
Copyright © 2011-2022 走看看