Shell执行python程序的缓冲区问题

环境:Linux
一段执行时间很长的Python程序在linux后台执行,把结果输出到某文件:

cmd='python  '$1' '$2' '$3' '$5' '$4
RESULT=eval $cmd
echo $RESULT

注:1,2,3,4,5为系统参数,指向Python文件及向Python传入的参数。
遇到的问题,程序没报错,echo却没有任何输出。
按照前一篇博客的方法可以解决这个问题,但是需要修改原有Python程序。现在提供一种新的解决方式:
修改shell如下:

cmd='python -u '$1' '$2' '$3' '$5' '$4
RESULT=eval $cmd
echo $RESULT

两者的区别是在python命令之后添加-u参数。
很多人对于python命令的参数不太清楚,其实可以使用man python命令查看:

PYTHON(1)                                                            PYTHON(1)

NAME
       python - an interpreted, interactive, object-oriented programming language

SYNOPSIS
       python [ -B ] [ -d ] [ -E ] [ -h ] [ -i ] [ -m module-name ]
              [ -O ] [ -O0 ] [ -R ] [ -Q argument ] [ -s ] [ -S ] [ -t ] [ -u ]
              [ -v ] [ -V ] [ -W argument ] [ -x ] [ -3 ] [ -?  ]
              [ -c command | script | - ] [ arguments ]

DESCRIPTION
       Python  is  an  interpreted,  interactive,  object-oriented programming language that combines remarkable power with very clear syntax.  For an introduction to programming in Python you are referred to the Python Tutorial.  The
       Python Library Reference documents built-in and standard types, constants, functions and modules.  Finally, the Python Reference Manual describes the syntax and semantics of the core  language  in  (perhaps  too)  much  detail.
       (These documents may be located via the INTERNET RESOURCES below; they may be installed on your system as well.)

       Python鈙  basic  power  can  be extended with your own modules written in C or C++.  On most systems such modules may be dynamically loaded.  Python is also adaptable as an extension language for existing applications.  See the
       internal documentation for hints.

       Documentation for installed Python modules and packages can be viewed by running the pydoc program.

COMMAND LINE OPTIONS
       -B     Don鈚 write .py[co] files on import. 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值