# Logstash file stops running at the point when it encounters stdout.read

**URL:** <https://discuss.elastic.co/t/logstash-file-stops-running-at-the-point-when-it-encounters-stdout-read/53660>\
**Category:** Logstash\
**Created:** [June 22, 2016, 1:35pm UTC](https://discuss.elastic.co/t/logstash-file-stops-running-at-the-point-when-it-encounters-stdout-read/53660 "2016-06-22T13:35:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![KaranPanchal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/karanpanchal/32/10477_2.png) [@KaranPanchal](https://discuss.elastic.co/u/KaranPanchal)\
**Post date:** [June 22, 2016, 1:35pm UTC](https://discuss.elastic.co/t/logstash-file-stops-running-at-the-point-when-it-encounters-stdout-read/53660/1 "2016-06-22T13:35:33Z")

</div>

I am running a logstash file to extract new fields from my csv file. I have written a python script that will bring the required value from my csv file. This python script will be executed in the ruby plugin in the filter section. I was refering to the following link to get my output:

> **[How to incorporate external utility scripts into Logstash Pipeline](http://vrepin.org/vr/Logstash-filter-external-script/)**
>
> This article describes the approach to call external applications from Logstash Pipeline and use their (JSON/XML/key-value) output in the further filtering process.

The problem I am facing is that my logstash file stops running after it gets output from python script.  
The output logstash file gives is the just the output of my python script and then it stops executing.

Following is my python script:

with open('/root/local/sample.csv','r') as csvfile:  
spamreader = csv.reader(csvfile,delimiter=',')  
i=0;  
for row in spamreader:  
if i == 0:  
header=row.index(sys.argv[2]);  
#print row,"\n"  
else:  
if row[0] == args[0] and row[2] == args[1] and row[1] == args[2]:  
data = row[header]  
sys.stdout.write(data)  
#print "Required row: %s" % row  
#print "Required Value: %s" % data  
i=i+1;  
csvfile.close();

Following is the filter section of my logstash file where I am executing python script:

if [RSRC\_TYPE] == "Value1"  
{  
ruby {  
code =\> 'require "open3"  
var = event["id\_val"]  
result1 = "/root/local/code.py Value1,value2,#{var} value3"  
stdin,stdout,stderr = Open3.popen3(result1)  
event["field1"] = stdout.read  
result2 = "/root/local/code.py Value1,value2,#{var} value3"  
stdin,stdout,stderr = Open3.popen3(result2)  
event["field2"] = stdout.read  
stdout.close  
stdin.close  
stderr.close  
'  
}   
}

Kindly help me to get out of this problem.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [July 4, 2016, 6:37pm UTC](https://discuss.elastic.co/t/logstash-file-stops-running-at-the-point-when-it-encounters-stdout-read/53660/2 "2016-07-04T18:37:16Z")

</div>

Use a translate filter instead.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 4:49am UTC](https://discuss.elastic.co/t/logstash-file-stops-running-at-the-point-when-it-encounters-stdout-read/53660/3 "2017-07-06T04:49:41Z")

</div>


