-1

I want to run nvidia-detect and capture the output in a list or even a string that I can do a string comparison of the output to what I require. I need to know if the system requires kmod-nvidia or kmod-nvidia-340xx.

I have searched and came up with two possible ways of capturing the output of nvidia-detect.

My initial code was:

test=str(os.system('nvidia-detect'))
print test

my output is: kmod-nvida 256

where 256 is the value of test.

So after searching I tried:

test2=subprocess.check_output('nvidia-detect', shell=True)

and get this error:

Traceback (most recent call last):
  File "/home/emmdom/PycharmProjects/mycode/nvidia_update.py", line 8, in <module>
    test2=subprocess.check_output('nvidia-detect')
AttributeError: 'module' object has no attribute 'check_output'
martineau
  • 119,623
  • 25
  • 170
  • 301
edom
  • 21
  • 1
  • 6
  • What version of python are you running? `python --version` and could you try running `python -c "import subprocess; print(dir(subprocess))"` to see if you can see the `check_output` function? – Scott Greenup Aug 03 '17 at 00:08
  • Also, could you post your entire program and how you are running it? – Scott Greenup Aug 03 '17 at 00:13
  • Hello Scott I am using ver 2.7 on rhel6 I have access to 3.x if I load the module or use an RHEL7 image but both give me the same error messages and results. The program is not complete this is the first part. I am testing that I can manipulated the output of nvidia-detect. Then I can move forward. – edom Aug 03 '17 at 06:32
  • import os import subprocess test = str(os.system('nvidia-detect')) print test test2 = subprocess.check_output('nvida-detect', shell=True) print test2 – edom Aug 03 '17 at 06:35
  • Sorry I could not get the code to format correctly – edom Aug 03 '17 at 06:35

1 Answers1

0

I got it work this is what ended up working for me. Thanks

import os

os.system('yum -y yum-plugin-nvidia nvidia-detect')
nvidia='kmod-nvidia'
nvidia_340='kmod-nvidia-340xx'

chk_nvidia=(os.popen('nvidia-detect').read()).rstrip()
print chk_nvidia

if chk_nvidia == nvidia:
   print 'nvidia'
   os.system('yum -y kmod-nvidia')

if chk_nvidia == nvidia_340:
    print 'nvidia-340-xxx'
    os.system('yum -y kmod-nvidia-340xx')
edom
  • 21
  • 1
  • 6