0

I have some questions about the subprocess function in python 2.7 I want to build an script that forms an if clause like:

Import os
Import subprocess
process = subprocess ('uname -a')
if process == 'ESXi':
    print ('yey')

I am sorry that the code has many mistakes and that my english is so poorly (motherlanguage greek)

8
  • What is your question? Commented Jan 10, 2018 at 19:48
  • How to check if the output value contains 'ESXi' Commented Jan 10, 2018 at 19:51
  • You want a substring match? stackoverflow.com/q/3437059/1531971 Commented Jan 10, 2018 at 19:52
  • Yes, just compared with the output value of the shell function uname -a Commented Jan 10, 2018 at 19:54
  • You should say this in the question body: I want to run a subprocess and get the results from "uname -a" as a string. I then want to test whether or not this result contains the string "ESXi". Commented Jan 10, 2018 at 19:56

1 Answer 1

0

to get the output of your command

word = 'ESXi'
process = subprocess.check_output(['uname','-a'])  
if word in str(process):   
   print ('yey')

result of your command will be in process

for more info (python doc) and example code

also, refer otheres question

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.