How to avoid os.system() printing out return value in python

前端 未结 4 893
一整个雨季
一整个雨季 2021-01-20 18:29

I\'m using Python to call bash to execute another bash script:

begin = int(sys.argv[1])
result = os.system(\"/tesladata/isetools/cdISE.bash %s\" %begin)
         


        
4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-20 19:13

    Actually, result is only the return status as an integer. The thing you're calling writes to stdout, which it inherits from your program, so you're seeing it printed out immediately. It's never available to your program.

    Check out the subprocess module docs for more info:

    http://docs.python.org/library/subprocess.html

    Including capturing output, and invoking shells in different ways.

提交回复
热议问题