I'm trying to utilize Charles Proxy's web interface feature that allows you to run Charles in headless mode and control Charles using curl commands to http://control.charles.
In terminal, when I run the following commands, I get my desired output:
Charles -headless &
curl -v -x <MY IP ADDRESS HERE> http://control.charles/session/start
curl -o session.chls <MY IP ADDRESS HERE> http://control.charles/session/download
I'm trying to reproduce these commands in Python using subprocess. Initially, I tried opening 3 different subprocesses for each of the commands above, only realizing that they all need to be within the same session.
Here's my implementation, but I'm not getting any output:
charles_init = subprocess.Popen(["/bin/bash"],stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
charles_init.stdin.write(b"Charles -headless")
charles_init.stdin.write(b"curl -v -x <MY IP ADDRESS HERE> http://control.charles/session/start")
charles_init.stdin.write(b"curl -o session.chls <MY IP ADDRESS HERE> http://control.charles/session/download")
Is the "&" in "Charles -headless &" relevant here? To my understanding, that "&" allows Charles to run in the background within a shell. Do I need to set shell=True when initially opening the subprocess?
If so, how do I avoid the security risks associated with shell=True?