I wanna to run cmd.exe to open url in default browser
-
objective: create url in python script; load page in default browser in win10 from npp python script.
status: aint got no satisfactioncode frag: I ran the following from console input area at bot of console one line at a time
x=r’cmd.exe start https:yahoo.com’
console.write(x) #show x on consoley=console.run(x)
console.write(y) #show y on console
console output:
Python 2.7.6-notepad++ r2 (default, Apr 21 2014, 19:26:54) [MSC v.1600 32 bit (Intel)]
Initialisation took 31ms
Ready.x=r’cmd.exe start https:yahoo.com’
console.write(x) #show x on console
cmd.exe start https:yahoo.com>>> y=console.run(x)
Microsoft Windows [Version 10.0.17134.706]
© 2018 Microsoft Corporation. All rights reserved.C:\Program Files (x86)\Notepad++>>>> console.write(y) #show y on console
help: what am I doing wrong?
start:http:yahoo.com #launchs yahoo in a new tab in my browser from a cmd window -
Not sure what the end goal truly is. If the goal is simply to open a url in a browser there are better ways. Python has process control commands, why not use them rather than trying some awful convolution with CMD.EXE?
-
@Alan Kilborn
my end goal is to simply launch a uri(constructed from text in my doc) in my default browser as a new tab I’m a python newbie.so if there are good, simple python ways to do what I want, I obviously don’t know where to start. I’m happy to follow any advice/pointers you’re ready to offer. let me know If you would like more backgound; the yahoo uri is just my quick test case, obviously does not work. Thanks in Advance, -
within the script you might do
import webbrowser webbrowser.open(r'https://notepad-plus-plus.org/community')
Just a note, if you are using PythonScript plugin you have to use python2 syntax.
Migration to python3 has not be done yet. and to add code like this to the forum
here, you can type~~~ YOUR CODE ~~~
-
@Raymond-Lew said:
help: what am I doing wrong?
I’ll assume that the forum formatting was what deleted your
//
, because what rendered ashttps:yahoo.com
would never work, since it’s reallyhttps://yahoo.com
.Notice you said “
start:http:yahoo.com
#launchs yahoo in a new tab in my browser from a cmd window”. And then you didn’t pass “start” to theconsole.run()
command? That was part of your problem. Unfortunately,start
is not an executable thatconsole.run()
can see. Instead, you have to tellconsole.run()
to launch cmd.exe, and tell cmd.exe to launch start, and tell start to launch the URL.The following sequence of interactive commands opened three tabs of yahoo.com in my default browser:
>>> console.run('cmd /c start https://yahoo.com/') 0 >>> url = r'https://yahoo.com/' >>> console.run('cmd /c start '+url) 0 >>> console.run('cmd /c start {}'.format(url)) 0
-
@kopalypse
Thank you for the webbrowser suggestion. I tried it and it gets me 90% to my objective.
on my PC It lauches a window in internet exploror 11, not my default browser. Thank you for the suggestion and I will look deeper down this path to see if I can change this default.@ PeterJones
your code samples and comments are perfect guidance for my knowledge level.
I have much to learn, thank you all for your responses.