⬆️ ⬇️

Working with the command line in Windows

From time to time, when reading articles on programming or manuals for any development, one has to deal with the need to execute code from a command line, for example

php -r 'echo "Hello, world!\n";' or svn checkout asido.googlecode.com/svn/trunk asido-read-only svn checkout asido.googlecode.com/svn/trunk asido-read-only .

As a rule, such teams are laid out by developers who work in Linux or other unix, in which they can be executed without any additional actions. A developer who works under Windows in order to execute this code has to be creatively reworked, for example, specify the full path to php.exe or create a working copy of the project through a familiar GUI by copying the path to the repository to the clipboard.



In order for this code to work, on unix-systems, symbolic links are created for the necessary executable files and placed in a directory ( / usr / bin , for example), the path to which is added to the PATH system variable. On Windows, this option (in my experience) is inconvenient and does not work. It is inconvenient because, firstly, the creation of symbolic links is possible only in NTFS, and secondly, the utility for creating them is not included in the standard delivery of Windows. But it does not work because after resolving a symbolic link, the current path becomes equal to the path of the directory in which the referenced file is located. Another option is to set the paths to all files in the PATH , but it will lead to its excessive cluttering and (at least theoretically) additional brakes in the system.



To get around these problems, you can use regular shortcuts. For all files that need to be run from the command line, we create shortcuts in some folder that is not on the system disk (just so that after reinstalling Windows, you do not have to create them in a new way). At the same time, for each of the shortcuts, we clear the “Launch Path” field, which is automatically filled when creating a shortcut. Otherwise, as in the case of symbolic links, the path will always be equal to the directory of the executable file.



After that, you need to add the path to the directory with shortcuts to the PATH variable (I have d: \ usr \ bin ), and add the LNK extension to the PATHEXT variable so that the * .lnk files can be run by analogy with * .exe , * .bat , etc. without specifying the extension. Since these manipulations (changing the value of system variables) have to be performed every time after reinstalling Windows, and you can just automate it, I did it. Here is the script .

')

Thank you maovrn for the idea .

Source: https://habr.com/ru/post/18565/



All Articles