3
2015-06-08 11:06:57 +08:00
@henryon
由于原始的比较复杂些,我简单写了个例子
我先写了个python 然后运行shell 然后运行awk 内容如下:
test.py
import veasyprocess
import os
cmd = "sh writefile.sh"
PWD = os.getcwd()
#veasyprocess模块中使用的就是subprocess.Popen方法,只是封装了下面两行
#fout=tempfile.TemporaryFile()
#subprocess.Popen(args=self.cmd.encode('utf-8'), stdout=self.stdout, stderr=self.stderr, shell=True, cwd=self.cwd)
status, outs = veasyprocess.shell_2_tempfile(_cmd = cmd, _cwd = PWD, _timeout = 240)
print status
print outs
============================================
wirtefile.sh
for((i=0; i<10; i++)); do
{
awk -f error.awk writefile.sh
}&
done
wait
error.awk
END {
for(i=0; i<10000; i++) {
printf "hello world 11111 22222 33333 44444 55555 66666\n"
}
}
~
输出内容有下面这种
hello world 11111 22222 33333 44444 55555 66666
1 22222 33333 44444 55555 66666
hello world 11111 22222 33333 44444 55555 66666
hello world 11111 22222 33333 44444 55555 66666
hello world 11111 22222 33333 44hello world 11111 22222 33333 44444 55555 66666
hello world 11111 22222 33333 44444 55555 66666
输出的内容明显有覆盖现象,要达到的效果就是数据无覆盖,即每行都是完整的hello world 11111 22222 33333 44444 55555 66666