1

I am new to Python, so any pointers are highly appreciated. I am running os.system("multiple commands here") but I am unable to get the output to a variable to display later. Also I am writing CGI script.

Here is what I am trying:

I am passing the IP variable which I am taking as input from user.

os.system("/usr/local/bin/nmap %s (ip)| grep tcp | awk -F '/' '{print $1}' ")

in bash this would be like

var=$(os.system("/usr/local/bin/nmap %s (ip)| grep tcp | awk -F '/' '{print $1}' "))

echo $var.

I want to do the same in Python 3.5 to echo this out on a browser.

I tried the os.popen approach but it errors out when I pass variable to it and I need to be able to pass variable in the command.

user6863772
  • 19
  • 1
  • 5
  • Possible duplicate of [Assign output of os.system to a variable and prevent it from being displayed on the screen](http://stackoverflow.com/questions/3503879/assign-output-of-os-system-to-a-variable-and-prevent-it-from-being-displayed-on) – Kieran Sep 22 '16 at 11:09

0 Answers0