1 / 73

Chapter 11

Chapter 11. Advanced Batch Files. Overview. This chapter focuses on batch file commands that allow you to: write sophisticated batch files further refine your technique in working with the environment . Batch File Commands. Batch files must …

garth
Download Presentation

Chapter 11

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 11 Advanced Batch Files Ch 11

  2. Overview This chapter focuses on batch file commands that allow you to: • write sophisticated batch files • further refine your technique in working with the environment Ch 11

  3. Batch File Commands Batch files must … • have the file extension .BAT • be an ASCII text file • include legitimate commands Ch 11

  4. Batch File Commands Any command used at the command line can be used in a batch file. Ch 11

  5. Batch File Commands Batch files have … • a limited vocabulary (commands) • a syntax • programming logic Ch 11

  6. A Review of the REM, PAUSE, and ECHO Commands REM command (remarks)… statements keyed in by user that tell what is the purpose of the batch file. Ch 11

  7. A Review of the REM, PAUSE, and ECHO Command PAUSE command … instructs the batch file to stop executing until the user takes some action. Ch 11

  8. A Review of the REM, PAUSE, and the ECHO Command Two ways to interrupt a batch file during execution: • Press <Ctrl> + C • Press <Ctrl> + <Break> Ch 11

  9. A Review of the REM, PAUSE, and the ECHO Command ECHO command … displays a command and the output of that command to the screen. Ch 11

  10. A Review of the REM, PAUSE, and the ECHO Command When ECHO is ON: • all commands in a batch file are displayed on the screen. Ch 11

  11. A Review of the REM, PAUSE, and the ECHO Command When ECHO is OFF … • can see the output of the command, but not the command itself. Ch 11

  12. Advanced Features of ECHO and REM To save valuable processing time, use a double colon (::) instead of the REM command. Ch 11

  13. Advanced Features of ECHO and REM To delete the display of even the message “1 file(s) copied”, use the device NUL. Ch 11

  14. Advanced Features of ECHO and REM Using NUL will not suppress a message such as “file not found”. Ch 11

  15. Advanced Features of ECHO and REM To suppress all messages use the command CTTY NUL. Ch 11

  16. Advanced Features of ECHO and REM When CTTY NUL is used, must follow with CTTYCON in order to have control of the console. Ch 11

  17. Advanced Features of ECHO and REM There is no such thing as a blank line in batch files. Ch 11

  18. Advanced Features of ECHO and REM To insert a blank line, key in ECHO followed by a period (ECHO.) Ch 11

  19. Ch 11

  20. The GOTO Command GOTO command … • will branch to a new line, creating a loop • works in conjunction with a label Ch 11

  21. The GOTO Command A loop will repeat steps until it is stopped by … • using an IF statement • breaking into the batch file with <Ctrl> + C Ch 11

  22. The GOTO Command A label … • is preceded by a colon (:) • can be no longer than 8 characters • is not a command Ch 11

  23. The GOTO Command GOTO has one parameter … • GOTO label Ch 11

  24. Ch 11

  25. The SHIFT Command The SHIFT command allows for an unlimited number of parameters on the command line. Ch 11

  26. The SHIFT Command SHIFT command … changes the position of the replaceable parameter in a batch file. Ch 11

  27. Ch 11

  28. The IF Command IF command … allows for conditional processing. Ch 11

  29. The IF Command Conditional processing … compares two items to determine if they are identical, or if one is greater than the other. Ch 11

  30. The IF Command The result of comparison testing is either a True or False value. Ch 11

  31. The IF Command True = items are identical False = items are not identical Ch 11

  32. The IF Command Syntax of IF command: IF <condition> <command> Ch 11

  33. The IF Command If a condition is True, the command will be executed. If a condition is False, the command will not be executed. Ch 11

  34. The IF Command The IF command checks for three conditions. Ch 11

  35. IF Command Using Strings To test whether or not one character string is exactly the same as another, use the IF command. Ch 11

  36. IF Command Using Strings The strings to be compared are separated by two equal signs (= =). Ch 11

  37. Ch 11

  38. Testing for NULL Values In a batch file it is sometimes possible to be caught in an endless loop. Ch 11

  39. Testing for NULL Values A value equal to “nothing” must be placed in a batch file to indicate when to end. Ch 11

  40. Testing for NULL Values NULL values … a user-defined value equivalent to nothing (no data). Ch 11

  41. Testing for NULL Values Testing for a null value involves using the IF command with quotation marks. Ch 11

  42. Testing for NULL Values Use quotation marks to test for null value: IF “%1” = = GOTO LABEL Ch 11

  43. Testing for NULL Values “If nothing is there, GOTO somewhere else” Ch 11

  44. Ch 11

  45. The IF EXIST/IF NOT EXIST Command IF EXIST/IF NOT EXIST command: checks for the existence or non-existence of a file. Ch 11

  46. Ch 11

  47. The IF ERRORLEVEL Command Testing Exit code … a code set by a program that indicates a True or False condition when the program finishes executing. Ch 11

  48. The IF ERRORLEVEL Command Testing IF ERRORLEVELcommand… a statement in a batch file that can test exit codes. Ch 11

  49. The IF ERRORLEVEL Command Testing An exit code is tested with ERRORLEVEL to determine if it is greater than or equal to it. Ch 11

  50. Ch 11

More Related