0

I can use only python 2.6.6 and subprocess is not working so I need to use only os module Below is the program

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 an output of one os.system to another os.system, I got the first os.system executed but for the second one i.e os.system(unit) is not coming because the output of os.system(var) should be assigned to a variable to wwn. could someone tell how to assign a variable to os.system(init)

Here in this script, the output of var says some X should be assigned to own but it's not taking X it's taking it as 0. So need your help to sort this why it is taking zero instead of X. Finally this X should be placed at init variable at {0}.

zwer
  • 24,943
  • 3
  • 48
  • 66
  • What do you mean `subprocess` is not working? Both `os.system` and `os.popen` are depreciated since Python 2.6 in favor of the `subprocess` module and you should be using it instead. – zwer Jul 02 '17 at 08:52
  • I dont know but whenever iam using the subprocess it is throwing error like no modules like tht.so any chamce that we can get this using OS module. – kalyanyellapu Jul 03 '17 at 15:14

1 Answers1

0

os.system does not return the output of the command - it returns the errorlevel.

If you need command output, use

wwn = os.popen(var).read()

That will assign the output from command var to wwn.

Be warned - the output is returned completely, with the trailing newline. You might want to strip() it before using it.

AbyxDev
  • 1,363
  • 16
  • 30