0

I have this command line text that I want to run inside my python script to the command line. Any suggestions on how to do this?

explorer "ms-drive-to:? 



destination.latitude=47.680504&destination.longitude=-122.328262&destination.name=Green Lake"
Johnny
  • 687
  • 1
  • 6
  • 22
  • Does it answer your question? [Calling an external command from Python](https://stackoverflow.com/questions/89228/calling-an-external-command-from-python) – Shredator Mar 17 '20 at 01:47
  • No it don't I tried that but it just opens my file explorer –  Mar 17 '20 at 02:10

2 Answers2

0

Sure, you can do something like is described in this post:

https://raspberrypi.stackexchange.com/questions/17017/how-do-i-run-a-command-line-command-in-a-python-script

Seems like you should use subprocess:

Running Bash commands in Python

gabroo
  • 34
  • 2
  • I tried that but it just open ups my file explorer. Like if you try running this: explorer "ms-drive-to:?destination.latitude=47.680504&destination.longitude=-122.328262&destination.name=Green Lake" from command line it goes to the maps in windows. –  Mar 16 '20 at 20:39
  • What do you want it to do instead? – gabroo Mar 17 '20 at 22:42
  • Glad to hear. Can you please mark it as best answer? – gabroo Mar 19 '20 at 03:01
0

If you want to effectively run this in python shell,like this: # it will open windows map

>>> !explorer "ms-drive-to:? 
destination.latitude=47.680504&destination.longitude=-122.328262&destination.name=Green Lake"

If you want to run in code, do like others method.All the answers are correct.

import os

command_str = 'explorer "ms-drive-to:? destination.latitude=47.680504&destination.longitude=-122.328262&destination.name=Green Lake"'
os.system(command_str)
# it will open windows map, and driving directions to Green Lake from your current location.

Be careful to use double quotes, single quotes will not be recognized correctly! results

windows uwp info: https://learn.microsoft.com/en-us/windows/uwp/launch-resume/launch-maps-app

Johnny
  • 687
  • 1
  • 6
  • 22