added gstat.err to Popen

This commit is contained in:
Marc Mance
2024-08-02 16:35:59 -04:00
parent 6e79655a28
commit d6c062b73d

View File

@@ -385,10 +385,6 @@ def welcome():
print("") print("")
def is_two_digit_number(number):
return 10 <= number < 100
def main(): def main():
welcome() welcome()
@@ -446,9 +442,14 @@ def main():
"15s", "15s",
] ]
with open("gstat.csv", "a") as output_file: gstatData = open("gstat.csv", "a")
# Create a Popen object with stdout redirected to the file gstatError = open("gstat.err", "a")
process = subprocess.Popen(gstat_command, stdout=output_file)
# with as output_file:
# # Create a Popen object with stdout redirected to the file
process = subprocess.Popen(
gstat_command, stdout=gstatData, stderr=gstatError
)
collect_data(minutes) collect_data(minutes)
@@ -456,6 +457,8 @@ def main():
if is_freebsd(): if is_freebsd():
process.terminate() process.terminate()
process.kill() process.kill()
gstatData.close()
gstatError.close()
except KeyboardInterrupt: except KeyboardInterrupt:
print("Caught Ctrl-C, cancelling collection...") print("Caught Ctrl-C, cancelling collection...")
@@ -463,6 +466,9 @@ def main():
if is_freebsd(): if is_freebsd():
process.terminate() process.terminate()
process.kill() process.kill()
gstatData.close()
gstatError.close()
exit() exit()
# Copy data files to /var/log (replace with appropriate copying function) # Copy data files to /var/log (replace with appropriate copying function)