# Running Python script without printing results

**URL:** <https://discuss.elastic.co/t/running-python-script-without-printing-results/271678>\
**Category:** Logstash\
**Created:** [April 29, 2021, 4:07pm UTC](https://discuss.elastic.co/t/running-python-script-without-printing-results/271678 "2021-04-29T16:07:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Felipe\_Fuller](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felipe_fuller/32/80377_2.png) [@Felipe\_Fuller](https://discuss.elastic.co/u/Felipe_Fuller)\
**Post date:** [April 29, 2021, 4:07pm UTC](https://discuss.elastic.co/t/running-python-script-without-printing-results/271678/1 "2021-04-29T16:07:26Z")

</div>

Hi Community!

I hope that you're doing great! I've been involved in a project, and we have to process data with a python script and then insert it with Logstash into Elasticsearch. Having that said, I use the exec plugin to execute the script, and then, I print the result in the script, such as: `print(response)`, so Logstash can detect and insert the data into Elasticsearch.

The problem is that this script is being logged in a monitor, and the output is sensitive data that shouldn't log.

Is there any way to pass the value through Python to Logstash output without printing in console, such as executing the script and just using `return response`?

An example of my Logstash pipeline would be the following:

```auto
input {
	exec {
		command => "/usr/bin/python3 /usr/share/logstash/pipeline/example.py"
		interval => 60
		codec => "json"
  	}
}
output {
	elasticsearch {
		index => "example"
		hosts => ["https://elasticsearch:9200"]
        user => "${ELASTIC_USERNAME}"
        password => "${ELASTIC_PASSWORD}"
        ssl => true
        ssl_certificate_verification => true
        cacert => '/certs/ca.crt'
        codec => json_lines
   }
   stdout {}
}

```

and a small example of a python script would be like:

```auto
def hello_world():
     hello_world = { "first_message": "hello world!" }
     
     print(hello_world)

if " __main__" == __name__ :
     hello_world()

```

The ideal way to do this would be to use `return hello_world` or something else to don't log the message in the console.

---

<div class="post-metadata">

**Author:** ![Cad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cad/32/86661_2.png) [@Cad](https://discuss.elastic.co/u/Cad)\
**Post date:** [May 15, 2021, 11:21am UTC](https://discuss.elastic.co/t/running-python-script-without-printing-results/271678/2 "2021-05-15T11:21:07Z")

</div>

Hi,

You have the possibility to implement the TCP protocol in the python script and configuring the logstash input ro get data from TCP protocol.  
For more informations see the [documentations](https://www.elastic.co/guide/en/logstash/current/plugins-inputs-tcp.html).

Cad.

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [May 15, 2021, 8:40pm UTC](https://discuss.elastic.co/t/running-python-script-without-printing-results/271678/3 "2021-05-15T20:40:28Z")

</div>

What is being logged? I would say that the cause is that you have a `stdout {}` output in the output block, this makes logstash prints out every message it process to the stdout with could be the terminal if you are running via command line, or a log file when running as a service.

Remove the `stdout {}` output and see if it solves your problem.

---

<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:** [June 12, 2021, 8:40pm UTC](https://discuss.elastic.co/t/running-python-script-without-printing-results/271678/4 "2021-06-12T20:40:38Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
