Skip to content
Advertisement

Executing shell commands in Python

I’m working in Linux/Python 3 and am creating some small scripts which consist of executing some commands inside of Python.

Example: Pinging a server

JavaScript

Output:

JavaScript

This is working OK but I don´t need to print everything. How can I get only the first line of the output?

Advertisement

Answer

You can use a subprocess in python3 to discard the output to devnull. Something like this

JavaScript

https://docs.python.org/3/library/subprocess.html#subprocess.DEVNULL

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement