我写了一个脚本,希望它可以在bash中通过 管道传递 。就像是:
echo "1stArg" | myscript.py
可能吗?怎么样?
看到这个简单的echo.py:
echo.py
import sys if __name__ == "__main__": for line in sys.stdin: sys.stderr.write("DEBUG: got line: " + line) sys.stdout.write(line)
运行:
ls | python echo.py 2>debug_output.txt | sort
输出:
echo.py test.py test.sh
debug_output.txt内容:
DEBUG: got line: echo.py DEBUG: got line: test.py DEBUG: got line: test.sh