{"id":8603,"date":"2015-02-22T17:37:34","date_gmt":"2015-02-22T17:37:34","guid":{"rendered":"http:\/\/www.oracletutoring.ca\/blog\/?p=8603"},"modified":"2015-02-22T17:44:33","modified_gmt":"2015-02-22T17:44:33","slug":"windows-a-little-batch-programming-towards-a-friendly-greeting","status":"publish","type":"post","link":"https:\/\/www.oracletutoring.ca\/blog\/windows-a-little-batch-programming-towards-a-friendly-greeting\/","title":{"rendered":"Windows:  a little batch programming towards a friendly greeting"},"content":{"rendered":"<h1>The tutor has wanted to place a greeting at the top of the Windows terminal (aka command prompt screen).\u00a0 Now you can too.<\/h1>\n<p>I heard about batch files &#8211; and saw files with the .bat extension &#8211; in the late &#8217;90s.  They weren&#8217;t necessarily new then; that&#8217;s just when I first saw them.<\/p>\n<p>A batch file is a plain text file that sends specific commands to other programs in the Windows system.  It might tell one to open, for instance.  It may also order the backup of a file.<\/p>\n<p>This little batch project consists of two programs:  one (called p1.bat) opens the command prompt, then initiates the second one.  The second one (p2.bat) prints a friendly greeting, then the date, atop the command prompt screen.<br \/>\n<span style=\"font-family:monospace\"><br \/>\np1.bat<br \/>\n<span style=\"color:olive\">@echo off<br \/>\ncmd \/k p2<\/span><br \/>\n<br \/>\np2.bat<br \/>\n<span style=\"color:olive\">@echo off<br \/>\necho Hello. Hope you&#8217;re well:)<br \/>\ndate \/t<\/span><\/span><\/p>\n<p>In p1.bat, <span style=\"font-family:monospace\">cmd<\/span> opens the terminal, while <span style=\"font-family:monospace\">\/k<\/span> keeps it open.  <span style=\"font-family:monospace\">p2<\/span> calls p2.bat to start.<\/p>\n<p>In p2.bat, <span style=\"font-family:monospace\">echo<\/span> prints the message that follows to the screen. <span style=\"font-family:monospace\">date<\/span> outputs the date, while <span style=\"font-family:monospace\">\/t<\/span> suppresses the option for the user to change it.<\/p>\n<p><span style=\"font-family:monospace\">@echo off<\/span> means that the actual commands are not printed to the screen, but just executed.<\/p>\n<p>As I can tell, batch programming uses the newline as a command separator.<\/p>\n<p>Batch programs need to be written in plain text, so not with a word processing program (unless you know how to switch its output to plain text).  In Windows, the plain text editor is Notepad.<\/p>\n<p>To write a batch program that opens the terminal and just prints &#8220;Cheers:)&#8221; at the top of the screen, you&#8217;d open Notepad and type a little file:<br \/>\n<span style=\"font-family:monospace;color:olive\"><br \/>\n@echo off<br \/>\ncmd \/k echo Cheers:)<br \/>\n<\/span><br \/>\nJust to be safe, you probably want to press <span style=\"font-variant:small-caps\">enter<\/span> at the end of the line &#8211; although it may not matter.<\/p>\n<p>Save the file as <span style=\"font-family:monospace\">cheers.bat<\/span>. You&#8217;ll probably want to give it its own folder.<\/p>\n<p>To execute the file, find it in its folder (using the file manager, rather than the terminal), then double click it.  Hopefully, the command prompt screen opens up with the friendly greeting <span style=\"font-family:monospace\">Cheers:)<\/span> at the top.<\/p>\n<p>I&#8217;ve used some very helpful sources for this article:<\/p>\n<p><a href=\"http:\/\/superuser.com\/questions\/106848\/batch-file-that-runs-cmd-exe-a-command-and-then-stays-open-at-prompt\">superuser.com<\/a><\/p>\n<p><a href=\"https:\/\/technet.microsoft.com\/en-us\/library\/bb490889.aspx\">microsoft.com<\/a><\/p>\n<p>Jack of <a href=\"https:\/\/www.oracletutoring.ca\">Oracle Tutoring by Jack and Diane,<\/a> Campbell River, BC.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The tutor has wanted to place a greeting at the top of the Windows terminal (aka command prompt screen).\u00a0 Now you can too. I heard about batch files &#8211; and saw files with the .bat extension &#8211; in the late &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.oracletutoring.ca\/blog\/windows-a-little-batch-programming-towards-a-friendly-greeting\/\"> <span class=\"screen-reader-text\">Windows:  a little batch programming towards a friendly greeting<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[105],"tags":[536,537,171],"class_list":["post-8603","post","type-post","status-publish","format-standard","hentry","category-computer-science","tag-batch-files","tag-batch-programming","tag-terminal-on-windows"],"_links":{"self":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/8603","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/comments?post=8603"}],"version-history":[{"count":32,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/8603\/revisions"}],"predecessor-version":[{"id":8635,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/8603\/revisions\/8635"}],"wp:attachment":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/media?parent=8603"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/categories?post=8603"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/tags?post=8603"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}