test.py:

#coding=utf-8
import subprocess
compilePopen = subprocess.Popen('gcc haha',shell=True,stderr=subprocess.PIPE)
compilePopen.wait()
print('the status code is:',compilePopen.returncode)
with open('log','w') as object:
object.write(compilePopen.stderr.read())

 

test.sh:

#!/bin/bash
while read str; do
    echo $str
done <readme.txt

 

sudo chmod +x test.sh
./test.sh

输出:

#coding=utf-8
import subprocess
compilePopen = subprocess.Popen('gcc haha',shell=True,stderr=subprocess.PIPE)
compilePopen.wait()
print('the status code is:',compilePopen.returncode)
with open('log','w') as object:
object.write(compilePopen.stderr.read())

 

相关文章:

  • 2021-05-06
  • 2021-04-18
  • 2022-12-23
  • 2022-12-23
  • 2022-02-10
猜你喜欢
  • 2022-12-23
  • 2022-02-28
  • 2021-08-16
  • 2021-08-01
  • 2022-12-23
  • 2022-01-07
  • 2021-09-12
相关资源
相似解决方案