Tuesday, April 4, 2017

Input prompt: Batch programming made easy

Also about this article could be the two sentences valid for most fairy tales: “Once upon a time …” and “And when they have not died …”. For long, it’s been a long time since the developers of the first operating systems thought out the DOS commands, which can be used mostly almost unchanged and even extended to the current Windows 8.1


Also interesting is


The commands are used to read and write to the system using the cmd.exe command interpreter (input prompt). You have already used some of these commands. This includes e.g. prompt. This will change the output of the text at the input prompt in the Cmd window. Or did you use color to change the foreground and foreground color of the input window, e.g. With color f0 switch to black font on white background?


Small programs to get used to


Also, the dir command should not be unknown to you, with the help of which you have output tables of contents for whole volumes or special folders. And then you have surely sent the file to the file path with the path> Destination Folder \ Pathname.txt


Shut down from the command line


Even if you have not dealt deeper with the topic of batch programming, you are sure to know this and a few other commands that can be used in the input prompt. But you are also always aware that they can be used because a translation program works in the input window. The Cmd interpreter, in the window you are completing, translates your input word-by-word during the program run, and


DIR and Robocopy


Line by line in machine commands. An important option of the cmd interpreter is that other programs can be called. These in turn can be interpreters themselves, which then allow access to their own commands within the context of the input window. One of these programs is e.g. Robocom.exe, which we will deal with in more detail.


Important: If such an interpreter is called, its commands, and not the Cmd interpreter, are applied. The window will be accepted by the new program. To return to the original window, enter exit as well as close the Cmd window


Before dealing with the most important commands, you should first adjust the input window to your own requirements. For example, you might want to use the input window as a user with administrative rights. To avoid password polling during your actions.


Place a shortcut to the input window on the desktop. Then open the context menu twice, once on the icon and then on the prompt. With Properties, you open a dialog box in which you have various options for change in several tabs. On the Shortcut tab, click Advanced. In the small add-on window, select Run as administrator.


Next, optimize the font, e.g. To Consolas, and the font size, e.g. To 28 pixels. Select the desired colors from the tab. Then change the height and width. This is also possible via tab layout in the Properties dialog, but it is better to close the dialog and manually open the window to the desired size. To ensure that the edges of your window do not exceed the screen dimensions. Place a shortcut on the desktop taskbar. When you next open, the changed properties are applied.


There are only two commands that allow you to change window properties from the code. Use Title = Title text to change the title and Color BF to change the background color (B) and the foreground color (F). For these, the 16 colors already defined under DOS are available, BASIC programmers are known as QBColor colors.


Get an overview of the available Cmd commands. Enter HELP in the input window. Use help> Drive: \ help.txt to copy the list into a text file for further processing. A functional list of the most important CMD commands can be found at the end of the article.


Download: File


After getting familiar with the commands, you should use them to create small programs for the exercise. The first program that we show you here contains some special features: Pythagoras hilf.


Functionality of foreign programs with batch use


The goal is to enter two numbers, then use the Pythagorean rules to calculate the hypotenuse from these two catheters of a right triangle. You will now learn about some of the most important rules of batch programming. How to enter values? How are variables used? What are the symbols for arithmetic calculations? Please consider the code


Please note: If you look at our first listing, you will certainly notice the line numbers. They are not part of the Cmd system and are only used by us to simplify the dialogs with you.


And this leads us to an essential property of batch files. You can create it with any editor that prints pure text without control characters. We use PSPad.


The first line shows some kind of comments. Comments are not viewed by the cmd interpreter as workable commands. The contents of these lines are not output. In line 2, the title, i.e. The title line of the input window. Line 3, cls, deletes the previously existing content of the window. Line 4 prohibits the output of commands.


Well of the commands, not the text, which is shown with the lines 6 to 9 to the information of the user. This is followed by two lines, in which (set / p) user input is expected. In the two lines (a = a or b = b), the entered values ​​are assigned to a variable. The variable name, followed by a description text that is displayed to the user, precedes the assignment operator, the equals sign. On line 13 the calculation is made ("% a% *% a%" + "% b% *% b%") and the assignment of the arithmetic result (set / a c = calculation). The calculation assigns the result of the addition of two multiplications as the sum of the variables c. Echo% c% prints the result on the screen. At the end, the pause command causes the c md window to be closed when the user presses a key.


An interesting variant of shutting down Windows is to switch to the hibernate state, English: hibernate, which is actually the winter sleep. This option saves the current screen, including all data and settings, on the computer and reads it again the next time it is started. This will speed up the computer.


Enter your input window, enter the line Shutdown / h, and confirm the entry. Depending on the size of your screen, the computer will shut down more or less quickly. When you restart, your complete state is restored before shutting down. This is much faster than a reboot. It is somewhat cumbersome to open the input request first and then enter the named line. This is easier to do with a shortcut on the tasklist.


Create a new shortcut on the desktop. As the location, enter Shutdown / h and the name Resting state. Attach the shortcut to the tasklist. Now simply click on the icon in the tasklist to initiate the rest state. Do you want to learn more about the Shutdown command? Then go to the input window and enter Shutdown /? on. A description of the functionality in American language is displayed in the window. Do you want to use the command better? Then just write a batch program. Our listing is an example.


With this code we can now save the detailed description of the text. Only so much: you've already met echo. Here comes the variant echo. With a point behind it. This will create blank lines on the screen. Also interesting is the jump cascade depending on the user input.


The jump mark begins with a double point and gets the name, which then appears in the same line.


Save the program to your PC. Create a shortcut on the desktop. Specify the complete file path as the location. As a name, it is recommended to shut down. If you now place your shortcut on the tasklist as a last action, a click, a keyboard input, and once enter button will be ready to close Windows comfortably.


The DIR command lists the contents of the current folder in the input window. With the / S parameter, the subdirectories are resolved and all files are displayed. Use this command to list all folders from a specific level. Use the pipe / redirection symbol> to enter the data into a file - also to be re-created. This then looks e.g. So from: dir / s> path \ Dir_Laufwerk.txt. All directories and files are listed


With the additional parameter / b, only the file names are output. In order to avoid having to enter this line at the prompt again, write a batch file. You can specify a file name in the drive to search. You should remember that the file will be added afterwards and there will be a first change.


Right from the beginning to the DOS commands was Copy. He's a bit picky about his syntax. This was followed by xcopy, already a lot more comfortable, now followed by robocopy.


Tip: Add long drive names to the src and dest variables using the clipboard. Use the context menu in the Batch window. It is important for all three copying functions that path names should not contain any spaces. And that you are accustomed to write down variable names.


The fre- quency is the control of foreign programs via batch commands. In order for you to access programs, these must provide appropriate interfaces. One of these requirements is IrfanView. IrfanView is a well-known, comfortable viewing and conversion program for image files of various types. In the File menu of IrfanView you will find a menu command Batch conversion / rename.


In order to control IrfanView via an external script, a large number of commands are available, which you can integrate directly into batch files. For a list of these commands, see the i_options.txt file. In Irfanview's program directory. A practical example: i_view32.exe /slideshow=c:\mypics.txt/closeslideshow. This will start a slide show from the images listed in the text file mypics.txt


We have compiled a number of possible irfan-batch functions in an external program: iview-Batch-Creator, which is also found on the mentioned homepage. The program creates batch programs for you which can be edited directly and adapted to your needs. It is largely self-explanatory and will provide you with good assistance when you start the batch programming.


All listings and an overview of CMD commands can be found here


Download: File

No comments:

Post a Comment