0

first of all, I'm a newbie to Ubuntu OS. I want to execute the Ubuntu terminal command ("sudo lshw -class disk") using python. how can I get the output as a string using the subprocess module in order to write the output into a text file?

In windows, I executed a similar task to this task by:

import subprocess

windows_info = subprocess.check_output(['powershell.exe','get-physicaldisk']).decode('utf-8')

f = open("hardDriveInfo.txt", "w")
f.write("Hard Drive Info" + windows_info)
f.close()
  • 1
    Does this help? https://stackoverflow.com/a/2502883/2681662 – MSH Oct 28 '21 at 07:23
  • 1
    Does this answer your question? [Store output of subprocess.Popen call in a string](https://stackoverflow.com/questions/2502833/store-output-of-subprocess-popen-call-in-a-string) – vladsiv Oct 28 '21 at 07:27

0 Answers0