0

More or less I am trying to make a script that uses chromium. I want to make it universal so it can be installed on any computer and work from there. Currently, I have to use the full path of the file to open it:

subprocess.Popen('C:\\Users\\name\\Desktop\\script\\chrome.exe bing.com')

this works fine, but i want to make it so it looks in the directory that it is being run from so it would be:

subprocess.Popen('chrome.exe bing.com')

How can I make this happen?

martineau
  • 119,623
  • 25
  • 170
  • 301
  • Does this answer your question? [subprocess.Popen using relative paths](https://stackoverflow.com/questions/21412610/subprocess-popen-using-relative-paths) – ruohola Dec 05 '19 at 00:59

1 Answers1

1

You could use the __file__ value, with something like this:

import os
import subprocess

subprocess.Popen([os.path.join(os.path.dirname(__file__) or '.',
                               'chrome.exe'),
                  'bing.com'])
Pierre
  • 6,047
  • 1
  • 30
  • 49
  • the "bing.com" portion of it is a chrome tick. when you add that to the end of the file path it opens chrome to that page. Not sure if that effects what you suggested, because it didn't work with or without it. Chrome wouldn't open at all – Cole Cirillo Dec 05 '19 at 01:17
  • To use parameters in `subprocess.Popen()` calls, you can either use a string, as you did, and add `shell=True`, or use a list of parameters (the first one being the binary). The second option is to be preferred for several reasons. – Pierre Dec 05 '19 at 01:21