zoukankan      html  css  js  c++  java
  • 不同语言从shell管道获取数据的方法

    shell:

    #!/bin/bash
    #==========================================================
    # this example show you how to get data from pipe
    #==========================================================
    while read line
    do
        echo $line
    done

    php:

    #!/usr/bin/env php
    <?php
    #========================================================
    #testing how to get data from pipe
    #========================================================
    $fp=fopen('php://stdin','r');
    $result='';
    while(!feof($fp)){
        $result.=fgets($fp,128);
    }
    fclose($fp);
    
    echo $result;

    python:

    #!/usr/bin/env python
    #coding:utf-8
    import sys
    
    #line=sys.stdin.readline()
    #while line:
    #    print line
    #    line=sys.stdin.readline()
    while True:
        line=sys.stdin.readline()
        if not line:
            break
        print line
  • 相关阅读:
    C语言中标识符的作用域、命名空间、链接属性、生命周期、存储类型
    循环练习
    ArrayList集合

    方法
    表单标签
    HTML基础
    二维数组
    一维数组
    switch选择结构
  • 原文地址:https://www.cnblogs.com/xiazh/p/2642270.html
Copyright © 2011-2022 走看看