简体   繁体   English

如何从python脚本内部运行一个url到命令行?

[英]How to run a url from inside a python script to command line?

I have this command line text that I want to run inside my python script to the command line.我有这个命令行文本,我想在我的 python 脚本中运行到命令行。 Any suggestions on how to do this?关于如何做到这一点的任何建议?

explorer "ms-drive-to:? 



destination.latitude=47.680504&destination.longitude=-122.328262&destination.name=Green Lake"

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 https://raspberrypi.stackexchange.com/questions/17017/how-do-i-run-a-command-line-command-in-a-python-script

Seems like you should use subprocess :似乎您应该使用subprocess

Running Bash commands in Python 在 Python 中运行 Bash 命令

If you want to effectively run this in python shell,like this: # it will open windows map如果你想在 python shell 中有效地运行它,像这样:# 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!小心使用双引号,单引号将无法正确识别! 结果

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM