Most Popular Posts

Jun 2, 2015

Introducing Java Async I/O

I’ve been playing with Java recently. It turns out Java has two archaic I/O stacks neither of which is adequate for modern days. That’s why I developed an async I/O package.

My package doesn’t replace the existing I/O stacks. It’s an upgrade on top of the old InputStream and OutputStream that enables async interaction to optimize CPU usage and responsiveness of the consuming app.

The entire source code is available on GitHub:

https://github.com/zlatko-michailov/async-io

Start with the README file, and you’ll find links to the binaries as well as to the documentation. Go through the doc articles and the API reference, and if this paradigm makes sense to you, try it in an app. I’ll be glad to hear your feedback.

Apr 13, 2015

Nuances of Command Piping in the Windows Command Shell

 

A key concept in command piping is the success/failure of the execution which is determined by the status code the command returns. 0 (zero) means “success” while any other value means “failure”.

Throughout this article, I’ll be using this successful command:

> cmd /c “exit 0

as well as this failing command:

> cmd /c “exit 42

Note: If you want to copy and paste some of these examples, make sure you fix the quotes, dashes, and other characters to their standard ASCII representations.

Execute on Failure ( || )

Executes the command on the right side if and only if the command on the left side has failed. This piped statement:

> cmd /c “echo left & exit 0 || echo right

prints “left” while this piped statement:

> cmd /c “echo left & exit 42 || echo right

prints “left” then “right”.

You can remember this syntax and behavior as the logical OR operation from the C language or its derivates – C++, Java, C#, etc.

Execute on Success ( && )

Executes the command on the right side if and only if the command on the left side has succeeded. This piped statement:

> cmd /c “echo left & exit 0 && echo right

prints “left” then “right” while this piped statement:

> cmd /c “echo left & exit 42 && echo right

prints only “left”.

Similarly to the previous one, you can remember this syntax and behavior as the logical AND operation from the C language family.

Execute in Parallel ( | )

You may be familiar with this one – this is the true pipe. The shell connects the stdout of the left command to the stdin of the right command.

What you may have not paid attention to is that the shell launches both of them in parallel. That is necessary for the pipe to have a live process on each end.

To demonstrate the parallelism, we’ll need to enhance/complicate our left command a little bit:

cmd /c "echo left begin >&2 & timeout /t 5 & echo left end >&2 & exit 0"

First it prints “left begin” (to stderr to avoid the piping, so we can see the output), then it sleeps for 5 seconds to simulate work, and then it prints “left end” right before exiting.

Success and failure don’t matter. Both of these piped statements:

> cmd /c "echo left begin >&2 & timeout /t 5 & echo left end >&2 & exit 0" | echo right

and

> cmd /c "echo left begin >&2 & timeout /t 5 & echo left end >&2 & exit 42" | echo right

print “left begin” and “right”, then sleep for 5 seconds, and then it prints “left end”.

Execute Sequentially ( & )

This is the simplest yet least popular of all variations – it executed the right command after the left command has finished regardless of success/failure.

Using the same commands from the previous section:

> cmd /c "echo left begin >&2 & timeout /t 5 & echo left end >&2 & exit 0" & echo right

and

> cmd /c "echo left begin >&2 & timeout /t 5 & echo left end >&2 & exit 42" & echo right

both of them print “left begin”, sleep for 5 seconds, then print “left end” and “right”.

Relationship to POSIX

The first 3 syntaxes are identical between Windows cmd and bash. What is ‘&’ in Windows is ‘;’ (semicolon) in bash. Otherwise the behavior is the same.

Feb 26, 2015

My US Patents

The following patent applications have been approved in the United States. To find out more about each of them, click on the patent number:

7,818,311 (2010-10-19)
Complex regular expression construction

8,856,792 (2014-10-07)
Cancelable and faultable dataflow nodes

8,909,863 (2014-12-09)
Cache for storage and/or retrieval of application information

About Me @ Microsoft (part III continued)

After multiple reorgs, my team continues owning the programmability and public API for SharePoint and now of the entire Office.

I, personally, have been focused on implementing Office cloud functionality to public app developers through the Office365 and Azure clouds:

I remain the primary reviewer and approver of public API changes in SharePoint.