I'm making a python script that will automatically check if nmap is installed on a computer and then proceed to run nmap. One problem I have is when it is run it comes back with /bin/sh: 1: [: missing ]
and I was also wondering how one would pipe the output of a terminal back into my program. Let's say I run hostname -I
how can I copy the output and assign it a variable name in my script. thanks the code is below
import os
import subprocess
def isInstalled(name):
cmd = """ if ! [ -x "$#(command -v """ + name + """)" ]; then
echo '0'
exit 0
fi"""
ret = subprocess.check_output(cmd, shell=True).strip()
if ret == b'0':
return False
return True
if isInstalled('nmap'):
print("Nmap is installed")
else:
print("nmap is uninstalled since quite mode is active auto install will")