Store os.system( 'curl -u "username:password" "https://<url>") in a python variable to stream data in another framework?

2.4k views Asked by At

I do a lookup on internet using CURL. I automated this using a python script to take an IP as an argument and further run CURL using that.

I tried the following:

maxm = os.system('curl -u  "Username : Password " %s' %url)

But still the output gets displayed on terminal and not as value for variable maxm.

I even tried subprocess.Popen. But that dint work though.

Seeking help to resolve this.

Regards Richa

1

There are 1 answers

1
laike9m On BEST ANSWER

You could use subprocess.PIPE, but the easiest way is to use subprocess.check_output

import subprocess

maxm = subprocess.check_output('curl -u  "Username : Password " %s' % url)