Monthly Archive: 六月 2018

Cool Skills: Launch applications from command line in Windows

Most of the time, we launch an application by double-clicking its icon on desktop. How about doing that in a special way? A way that makes you different from everyone around you, a way that is more convenient sometimes, a way that is more coder-styled, the most important, a way that makes launching an application become a COOL thing!

Questions to forward, well at first, I’d like to show you how I lunch an application from a command line:

As you can see, firstly, press down win+r, input cmd, and then hit Enter, the command window turns up. I launched chrome by inputting start chrome, and then, hit Enter. Soonly, the chrome window showed up. So, how do I launch it by typing start chrome in command line? Well actually, this is very simple, all you need to do is to move or copy your applications’ launching shortcuts into a single folder, then, add the folder’s path to environment variables. The command START is a built-in command in Windows, use it to execute an executable file(.exe), you’ll get it launched!

Gather your launching shortcut into a single folder

For example, I move my Chrome shortcut into a folder and renamed it to “chrome”, the folder’s path is “E:\path”. Don’t forget the path!

Add the path to environment variables

There is a variable named “path” in environment variables, add “E:\path” to path.


Verify it!

If you did everything right, input start chrome and hit Enter in command line, Chrome browser should appear.


Also, you can create a shortcut of your path folder, rename it like “openpath”(this is how I did it), and move it into this folder itself! So when you need open this folder to add or remove shortcuts, you can simply input start openpath, the folder will show up immediately!

The transformation of urllib2’s usage in Python3

Usage of urllib2 in Python

In Python, we can simply type the following code to import urllib2:

import urllib2

Then, urllib2.Request(host) and urllib2.urlopen(request) is available to use:

request = urllib2.Request(host)
response = urllib2.urlopen(request)

But, when it comes to Python3, a newer version of Python which has a lot differences with Python2, things gonna has to change!

Usage of urllib2 in Python3

In Python3, we cannot just type “import urllib2” to get it done, you’ll find an error message “No module named urllib2“. This is because of a different usage of urllib2 in python3. The following is my current solution:

Use the following code to import:

from urllib.request import Request

Then, here is how I use them: