moved file check into statcollect function only if results are true
This commit is contained in:
16
ifstat.py
16
ifstat.py
@@ -16,14 +16,6 @@ headerRow = [
|
||||
|
||||
filename = "ifStat.csv"
|
||||
|
||||
# Check if the file exists
|
||||
if not os.path.exists(filename):
|
||||
# Create the file in write mode ('w') if it doesn't exist
|
||||
with open(filename, "w", newline="") as csvfile:
|
||||
csv_writer = csv.writer(csvfile)
|
||||
# Write the header row (optional)
|
||||
csv_writer.writerow(headerRow)
|
||||
|
||||
|
||||
def runifstat():
|
||||
# Run the command and capture output
|
||||
@@ -36,6 +28,14 @@ def runifstat():
|
||||
|
||||
# Check the return code (0 for success)
|
||||
if result.returncode == 0:
|
||||
# Check if the file exists
|
||||
if not os.path.exists(filename):
|
||||
# Create the file in write mode ('w') if it doesn't exist
|
||||
with open(filename, "w", newline="") as csvfile:
|
||||
csv_writer = csv.writer(csvfile)
|
||||
# Write the header row (optional)
|
||||
csv_writer.writerow(headerRow)
|
||||
|
||||
# Access the captured output as a string
|
||||
output = result.stdout
|
||||
|
||||
|
||||
Reference in New Issue
Block a user