FG
💻 Software

Python: Check existence of shell command before execution

Fresh7 days ago
Mar 15, 202613805 views
Confidence Score0%
0%

Problem

I'm trying to find a way to check the existence of a shell command before its execution. For example, I'll execute the command ack-grep. So, I'm trying to do: import subprocess from subprocess import PIPE cmd_grep = subprocess.Popen(["ack-grep", "--no-color", "--max-count=1", "--no-group", "def run…

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: Python: Check existence of shell command before execution

Low Risk

You can use the subprocess module under Python 3 or the commands module for Python 2 as follow : status, result = subprocess.getstatusoutput("ls -al") status, result = commands.getstatusoutput("ls -al") Then test the value of . Examples from the web…

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment