0

Below is the script for searching a input data in a given OS.system command ( copied to file out.txt) and prints the line of the given input data. Now I want to put the output i.e line in another OS.system command. For example symaccess -sid 567 show -name xxx -type init where xxx is the output of the previous OS.system command i.e line.

Note - I can use only python 2.6.6 and the scripts related to storage

import os
os.system('symaccess -sid 456 list -type init > out.txt')
server = raw_input("server name:")
with open('out.txt', 'rt') as in_f:
     for line in in_f:
              if server in line:
                 print line

I used another method as below import os server = raw_input("server name:")

var = "symaccess -sid 239 list -type init | grep \"{0}\"".format(server)

wwn = os.system(var)

init = 'symaccess -sid 239 -type init show {0}'.format(wwn) print init os.system(init)

above is the script i used to add a output of one os.system to another os.syste,. i got the first os.system executed but for the second one i.e os.system(init) is not coming because os.system(var) should be assigned as a variable.could someone tell how to assign a variable to os.system(init)

  • import os server = raw_input("server name:") var = "symaccess -sid 239 list -type init | grep \"{0}\"".format(server) wwn = os.system(var) init = 'symaccess -sid 239 -type init show {0}'.format(wwn) print init os.system(init) – kalyanyellapu Jun 22 '17 at 01:10
  • above is the script i used to add a output of one os.system to another os.syste,. i got the first os.system executed but for the second one i.e os.system(init) is not coming because os.system(var) should be assigned as a variable.could someone tell how to assign a variable to os.system(init) – kalyanyellapu Jun 22 '17 at 01:13

2 Answers2

4
import subprocess
cmd= 'ls'
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
std_out = p.communicate()

Here is a possible way to access the output in Python.

Joey Allen
  • 381
  • 1
  • 4
  • 12
0

Try using "subprocess.checkoutput()".

import subprocess
import os
output = subprocess.check_output(['symaccess -sid 456 list -type init'])
os.system(output)
  • subprocess.checkoutput() is New in version 2.7. OP needs 2.6.6 (though may have added this after your answer). – Wyrmwood Jun 21 '17 at 20:23