#๐Ÿ”’ Need help with subprocess.Popen

4 messages ยท Page 1 of 1 (latest)

viscid ridge
#

I have small portion of a solution that I am having difficulty with.

I am using Selenium and chromedriver to drive an instance via remote debugging port.

In a nutshell this is what I am trying to do:
Launch a remote debugging chromedriver instance at the beginning of the script that does not occupy the terminal, and not close the instance when the script is terminated

I'd like to have it all in a single script, if possible. Currently, I have a separate script that I call from my main script.

What is the best practice for this type of scenario?

Current code:
(script to launch chromedriver)

`from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options

Path to chromedriver executable

CHROMEDRIVER_PATH = 'c:\chromedriver\chromedriver.exe'

Set up Chrome options

chrome_options = Options()
chrome_options.add_argument(
"--remote-debugging-port=9222") # Specify remote debugging port
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument("--start-maximized")

Start a Selenium session and connect to the debugging instance

driver = webdriver.Chrome(service=Service(CHROMEDRIVER_PATH),
options=chrome_options)

input("Press 'enter' to kill Chromedriver.")`

From my main script, I am calling this (in its exe form)

`def start_remote_chromedriver():
subprocess.Popen(['/1.exe'],
creationflags=subprocess.CREATE_NEW_CONSOLE,
close_fds=True)

start_remote_chromedriver()

Do other stuff.`

For the life of me, I cannot figure out how to achieve the same thing from a single file. I am new to Python (and any coding beyond amateur level), so I don't know if this is possible, advisable, dumb, good, or none?

I am looking for any feedback. I don't know a single person in real life to talk to about this stuff. LOL Thanks in advance.

sturdy plankBOT
#

@viscid ridge

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

sturdy plankBOT
#

@viscid ridge

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.