Search code examples
pythonarrayscommandcommand-line-interfacessid

How to easily transform CLI output into a String


im trying to get a list of SSID's into Display

After a while I found that the CLI Command im looking for is

nm-tool | grep "Infra"  | cut -d " " -f5-7

What shows me the SSID's I need, but now I want to create a variable on Python using this output. When I just record it in a variable it turns it into a interger with value 0, but what I want is an array where I can use

ArrayName[0] = First SSID ArrayName[1] = Second SSID


Solution

  • I suspect you are using subprocess.call since you said you are getting an integer return type. Instead you probably want to use subprocess.check_output. https://docs.python.org/2/library/subprocess.html Use a combination of subprocess.check_output to run the command and then str.split to split the data into an actual list rather than a single string.