Book announcement - Batchography: The Art of Batch Files Programming

About the forum and SS64 (errata, changes, feedback, suggestions.)
Post Reply
User avatar
MigrationUser
Posts: 336
Joined: 2021-Jul-12, 1:37 pm
Contact:

Book announcement - Batchography: The Art of Batch Files Programming

Post by MigrationUser »

03 May 2016 14:27
elias

Hello fellow CMD scripters and Batch files programmers,

I am following the forums' rules and this post is not a 3rd party service or website advertisement. I am all in favor of knowledge and this post is just a book announcement.

Batch files scripting was the first language I learned. For that reason, I decided to write a comprehensive book about the language as a commemoration.

I would like to announce the book because it is detrimental beneficial and helpful for system administrators, programmers and other users.

Along with SS64 site which has been given due credits in the book, you will also find this book very useful.

It is entitled: "Batchography: The Art of Batch Files Programming"

Google it. It is available on TheBookPatch for now and will be available on Amazon in ~two weeks.

It is my hope that after you read this book, you will feel more confident writing more scripts.

In the Batchography book, you will learn about:

Code: Select all

* The Basic concepts of Batch file scripting        * Data structures: Arrays, Stacks, Sets, Maps, etc...
* Multiline, compound and conditional statements    * Building Batch Files libraries
* Function calls and repetition control structures  * Files and strings manipulation techniques
* Debugging and troubleshooting tips                * Coding conventions and testing methodologies 

As a bonus, the book also includes the Hangman game completely written using the Batch files scripting language!

Are you ready to begin this learning endeavor and earn yourself the Batchographer title?
This is my first self published book and I would love your support.

I hope you like it.

Last edited by elias (03 May 2016 17:54)

Book: Batchography - The Art of Batch Files Programming

----------------------------

#2 03 May 2016 15:55
Shadow Thief
elias wrote:

I would like to announce the book because it is detrimental
http://www.oxforddictionaries.com/defin ... etrimental

I'll be sure to avoid it, then.

----------------------------

#3 03 May 2016 16:24
Shadow Thief

But seriously, if I could see some sample pages, that would be immensely helpful before I drop $35 on a book.

----------------------------

#4 03 May 2016 17:53
elias
Shadow Thief wrote:

elias wrote:

I would like to announce the book because it is detrimental

http://www.oxforddictionaries.com/defin ... etrimental

I'll be sure to avoid it, then.
You caught me! A Freudian slip: with the new found knowledge from reading the book, you might become dangerous and get into all sort of trouble! wink

I tell you what, I would like to send you a free copy if you PM me a shipping address.

Last edited by elias (03 May 2016 17:55)

Book: Batchography - The Art of Batch Files Programming

----------------------------

#5 03 May 2016 18:06
Shadow Thief

ss64 doesn't seem to have a PM system, but I've sent you an email.

----------------------------

#6 04 May 2016 13:35
npocmaka

Your other two books have fairly good reviews:

https://www.amazon.com/gp/product/1119028752?tag=ss64
https://www.amazon.com/gp/product/1118787315?tag=ss64
https://www.goodreads.com/book/show/182 ... ngineering
https://www.goodreads.com/book/show/265 ... s-handbook

And currently you are working for M$ smile .

If there's a kindle edition probably I'll take a look (but I'll also prefer to take a look at sample pages and contents page)
I suppose you can even post the contents page here?

----------------------------

#7 04 May 2016 17:56
elias

Hello npocmaka,

Thanks for your feedback.

This is my first book as a main author and self-publishing. I am not relying on any services from publisher (like I did for Wiley publishing for the previous two books).

I did the cover design, formatting, the writing, the proof reading and everything else. This turned out to be a huge learning experience and required lots of efforts.

I don't expect the Batchography book to be perfect but I believe I have done a great job demystifying the Batch Files programming language and making it easy for newcomers. That's my hope at least.
If you are a veteran Batch files programmer then perhaps you won't learn a ton of new things but maybe a few tricks here and there.

Because of all the efforts involved in this book, I am not going to release an e-book version until I sell a number of copies and feel I recovered my expenses.

Pirates show no mercy: once it is an ebook then it is pirated and gets distributed on pirate sites...

Piracy will discourage me from writing more books if that happens early on. I hope you understand that.

Here's the table of contents:

Code: Select all

INTRODUCTION 
	What are Batch files?
	Who is this book for?
	How to best read this book?
	Conventions used in this book
	What does the book cover?
	More Batch files scripting material

CHAPTER 1 – BATCH FILES SCRIPTING LANGUAGE BASICS 
	Getting started
	CMD keyboard shortcuts and other tips
	Customizing the command prompt
	Recalling commands with keyboard shortcuts
	Creating commands aliases with the DOSKEY utility
	Automatically running a script when the command prompt starts
	Path completion shortcuts
	Editing tips
	Useful commands
		COLOR
		ASSOC/FTYPE
		TYPE
		CLIP
		RUNAS
		DIR/COPY/XCOPY/MOVE/RENAME/DEL
		PUSHD/POPD/CD/CHDIR/MD/MKDIR
		Using the WMIC tool
		Using the REG command to work with the registry
		Process management commands
	Command echo
	The “Errorlevel”
	Command extensions
	Breaking long commands into multiple lines
	Executing multiple commands on the same line
	Compound statements
	Conditionally executing multiple commands on the same line
	Comments
		Comments at the beginning of the line
		Comments at the end of the line
		Multi-line comments

	Escaping special symbols
	Passing command line arguments
		Using the SHIFT keyword

	Command line arguments and FOR loop variables modifiers
	Environment variables 
		Manipulating environment variables
		Useful environment variables
		Localizing the environment variables block
		Delayed environment variables expansion
		Two-level environment variables expansion
		Using the SETX command

	Labels
		The EOF label
		Function calls
		Checking the existence of a label

	Taking input from the user
	Standard Input/Output redirection
		Special files and devices
		Using output redirection in Batch file scripts
		Using input redirection in Batch file scripts
		Mixing input and output redirection
		Pipes
		Chaining pipes

	Arithmetic operations
	Summary

CHAPTER 2 – BATCH FILES PROGRAMMING 
	Conditional statements 
		Multiline commands
		Checking the command line arguments
		Extended syntax
		Switch/Case syntax

	Repetition control structures 
		The FOR keyword
		Extended FOR keyword syntax
		The FORFILES command
		Nested FOR loops
		Using the GOTO and IF

	String operations
		String substitution
		Sub-string
		String concatenation
		String length
		Using variable parameters with string operations
		String sorting
		Using the FINDSTR command

	Basic data structures
		Arrays
		Multi-dimensional arrays
		Associative arrays
		Stacks
		Sets

	Summary
	Test your skills

CHAPTER 3 – CODING CONVENTIONS, TESTING AND TROUBLESHOOTING TIPS
	Coding conventions
	Variables naming conventions
		Avoid environment variable collision
		Labels naming conventions

	Persisting changes beyond the ENDLOCAL call
		Using compound statements
		Using the exit code
		Using the FOR loop variables
		Using temporary files

	Writing recursive functions
	Parsing command line arguments
	Batch files calling other Batch files
	Building, testing and using a utility Batch file script library
		Testing the library

	Debugging and troubleshooting tips
		ECHO is your friend
		Making your script debug-ready
		Dumping the values of the work and state variables
		Other tips

	Summary

CHAPTER 4 – BATCH FILES RECIPES
	Simple console text editor
	Check if the script has administrative privilege
	Looking for a specific privilege
	Checking if system directories are writable
	Using known commands that fail to run without elevated privileges
	Stateful Batch file scripts
	Resumable Batch files
	Converting ordinals to characters
	Convert a string from upper case to lower case and vice versa
	Extracting embedded text files
	Embedding and extracting binary files and executables
	Embedding foreign scripts inside your Batch file script
		Embedding Python code in your Batch file script
		Embedding JScript code in your Batch file script
		Embedding Perl code in your Batch file script
		Embedding PowerShell code in your Batch file script
		Embedding any other script in your Batch file

	Getting files information
		Getting file’s last modification time
		Getting file’s attributes
		Getting a file’s size
		Triggering a command when files are modified in a directory
	
	Get the version string of MS Windows
	Creating a compressed archive containing all your version controlled source files
	Parsing INI files
	Interactive Batch file scripts
		Simple menus
		Dynamic menus

	Time for fun – Let’s play hangman!
A new comer to the language will read and learn Batch files programming as if he/she has picked up a Python or C/C++ book.
You can see the progression of the book from its table of contents.

I hope the Batchography book benefits the CMD and Batch files programming community.

Last edited by elias (04 May 2016 17:59)

Book: Batchography - The Art of Batch Files Programming

----------------------------

#8 05 May 2016 14:06
npocmaka

Thanks.
The last chapter looks interesting.
Is there a reason to skip VBScript embedding in batch files as there is a flawless technique to do this?

I consider VBscript as important because it is installed by default and supports passing by reference (while jscript does not).This important because there are plenty of wmi classes functions that rely on passing by reference in order to emulate returning more than one variables as result.

Are the macros mentioned there?

Last edited by npocmaka (05 May 2016 17:15)

----------------------------

#9 11 May 2016 01:04
elias

Hello npocmaka,

I think because I rarely used VBScript myself and that's why I did not include it. My intent was to have the book with 120 pages but I kept adding essential topics. It became 300 pages full of most basic to advanced topics for beginners and intermediate readers. I had to cut out a lot of material out.

No I don't talk about those macros you mentioned, instead, I mention DOSKEY's macros.

By the way, the book is now out on Amazon here:

Batchography: The Art of Batch Files Programming

and will be shipped to US buyers only at the moment.
I will sign the book with the name of the buyers before I ship it.

I would love some feedback on the material if you get to buy the book and read it.

Book: Batchography - The Art of Batch Files Programming

----------------------------

#10 18 May 2016 18:52
elias

Hello friends,

The ebook is out: http://amzn.to/1rTQsZP

Book: Batchography - The Art of Batch Files Programming

----------------------------

#11 26 May 2016 20:32
npocmaka

I've bought the book and took a glance.
Looks good and is better than the MS documentation.I liked the set (data structure) and stack implementation.
Though I have some points to share.

1.Embedding a binary in a batch.When base64 certificate is used there's no need of additional file. Certutil will take everything between begin/end certificate so you can use directly the batch file itself.And this can spare a lot of expensive IO operations :

Code: Select all

@echo off

del /q /f pointer.jpg >nul 2>nul
certutil -decode "%~f0" pointer.jpg
hh.exe pointer.jpg
exit /b %errorlevel%

-----BEGIN CERTIFICATE-----
/9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAAMgAA/+4ADkFkb2Jl
AGTAAAAAAf/bAIQACAYGBgYGCAYGCAwIBwgMDgoICAoOEA0NDg0NEBEMDg0NDgwR
DxITFBMSDxgYGhoYGCMiIiIjJycnJycnJycnJwEJCAgJCgkLCQkLDgsNCw4RDg4O
DhETDQ0ODQ0TGBEPDw8PERgWFxQUFBcWGhoYGBoaISEgISEnJycnJycnJycn/8AA
EQgACgAKAwEiAAIRAQMRAf/EAFsAAQEBAAAAAAAAAAAAAAAAAAAGBwEBAQAAAAAA
AAAAAAAAAAAAAAEQAAIBAwQDAAAAAAAAAAAAAAEDAgARBSExIwQSIhMRAQEBAAAA
AAAAAAAAAAAAAAARIf/aAAwDAQACEQMRAD8A13PZ5eIX3gO8ktKZfFPksvQ8r4uL
ecJmx1BMSbm8D6UVKVcg/9k=
-----END CERTIFICATE-----

2.String length - you've choose pretty ineffective algorithm to get the string length. I suppose this is due ti you didn't want to paste a code with not clear IP?

3.May be this way of embedding javascript code into batch is better.Directives will work only with jscript.net and wsh version of jscript. But with the trick in the link you can use it with node.js,typerscript and so on.

4.Much better way to combine powershell and batch

5.You can archive files and folders without external binaries

that's for now.

----------------------------

#12 31 May 2016 01:35
elias

Hi npocmaka,

Thanks for your comments and for getting the ebook.

1)
I was not aware of that!

Indeed that would be so fast!

The idea of the example was to show how to generically solve this problem if the certutil was not smart enough AND to give an idea on how one can embed various base64 encoded files in the Batch file, extract them to temp and convert them back to binary.

2)

I was not aware of the page you mentioned, however I do mention in the book "strlen-fast" and explain it. I found that somewhere on stackoverflow.com. Now that you gave me the link, it looks it is the strlen7 implementation actually.

Again, I do the slow implementation to teach the readers how to express ideas and concepts using the Batch language. It is up to the reader to come up with a faster method after s/he learned the language syntax.

3 + 4)

Thanks again, this is neat!

5)
Are you talking about the "git archive" example?

Please explain.

Thanks.

Book: Batchography - The Art of Batch Files Programming

----------------------------

#13 31 May 2016 16:26
npocmaka
elias wrote:

Hi npocmaka,

5)
Are you talking about the "git archive" example?

Please explain.

Thanks.
Yes. It is about the the git archive.Powershell 5.0 has Compress-Archive and Expand-Archive cmd-lets.
You can also use MAKECAB or Shell.Application object through ActiveX object.

----------------------------

#14 29 Jun 2016 17:56
Simon Sheppard

I have now read enough of this book to add it to my list of recommended books here: https://ss64.com/links/windows.html

It isn't very often we get a new book on the subject of batch file scripting, so I'd just like to thank Elias for writing this one and sending me a copy to review.

original thread: https://ss64.org/oldforum/viewtopic.php?id=2136
Post Reply