-1

My code requires that UFW (Uncomplicated firewall) is installed. The program will only be run on a Linux based OS. How would I go about having Python return a value if it finds UFW installed?

Edit: Instead of catching the output, I want to see if the folder (in the default installation path) exists.

4

1 Answer 1

1

Please note this is just an edited copy of links

  1. How do I check if directory exists in Python?
  2. Check if a program exists from a python script

Hope This helps

import subprocess
rc = subprocess.call(['which', 'ufw'])
if rc == 0:
    print('ufw installed!')
else:
    print('ufw missing in path!')

# To check whether path exists
import os

if os.path.exists("/usr/sbin/ufw") :
  print("path exists")
else:
  print("path doesn't exist") 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.