0

Hello!
I was looking for an answer to the question how to run any program from a python script level without knowing the exact path to the program?
Here's an axample:

If I type in my console (console in Spyder or PyCharm)

Open Spotify

Then my program should open Spotify application.
When I was looking for an answer to this question, I only found cases with a specific file location.
Thank you in advance for your time. I'm beginner so sometimes I find it hard to come across to solution.

3
  • 2
    Which operating system are you using? On linux I can just do import subprocess then subprocess.run("spotify"), because installing Spotify with sudo snap install spotify adds a spotify executable to my bash PATH. Commented Jan 4, 2021 at 18:51
  • I'm using Windows 10 Commented Jan 4, 2021 at 18:53
  • 1
    You will have to figure out how to open an application from the command line prompt on windows then use subprocess.run to execute that command. google.com/search?q=run+application+from+cmd+by+name+windows Commented Jan 4, 2021 at 18:55

1 Answer 1

1

I don't know of a way; as far as I know, you have to know the file location, so to achieve what you want, you need to write some code that will dig through files to find the file location. Ideally, you know the program is contained somewhere in your programs folder (or else it gets harder). os.listdir is a function that can read a folder and list the files inside. You could write a recursive program that looks in your programs folder, checks for spotify, then lists the folder inside it, then checks in each of those...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.