Sunday, December 9, 2018

C++ Map With Multiple Keys

I recently had need for a C++ collection which could be accessed with multiple keys.  Specifically, I had an object that I wanted to look up either by name or id (in O(1) time).  One way to do this is to create two unordered_maps – one keyed by id and another by name, but that is error-prone.  I ended up finding a boost class which will do this. It took me a while get it working, so I thought I would share the result.

Sunday, February 11, 2018

Building the Perfect Ergo Workstation

Over the last few years, I've been evaluating the ergonomics of my workspace and making improvements.  That is, I've been trying to be proactive about the health problems that come from sitting at a desk full time (sitting is the new smoking, and all that.).

Along the way, I've done way too much research and plenty of tinkering, so I decided to share what I've learned.  I will try not to recycle what has already been written on the topic, but instead point to other resources for additional reading.  The purpose of this post is to share the products I have found and modifications I have made to those products in my quest to improve my workspace ergonomics.

First, a few tidbits...


The single best thing you can do for your health is get regular exercise.  No fancy ergo chair or standing desk will make up for lack of exercise.  Find a way to get your 30 minutes/day (minimum).

Also, take regular breaks during the workday.  I have personally started taking a 5 minute "movement break" every 30 minutes.  It extends the length of my workday slightly, but it is absolutely worth it.  I had a chiropractor explain to me that many of the back issues which develop from sitting all day are caused by lack of movement, not just downward pressure on the spine.  Movement is key.  Buying a standing desk and standing all day is no better than sitting all day.  Research is showing that micro-breaks are good for your health.

During these breaks I typically try to move in ways which I otherwise wouldn't.  For example, I do this routine regularly.  I use the Stretchly to remind me to take them.  Personally, I have found dynamic movement to be far more helpful than traditional stretches.


Some (but not all) of the products mentioned here are expensive.  In some cases, there are cheaper options which might be suitable.  However, consider the cost compared to the medical bills that will come from improper ergonomics.  Only go cheaper if you can do so without large compromises in the ergonomic quality.

Also, these things can be purchased as money allows.  My personal order of importance would be as follows:

  1. Microbreaks (free!)
  2. Ergo keyboard (cheap)
  3. Ergo mouse (cheap)
  4. Sit-to-Stand desk
  5. chair
  6. Seat cushion (cheap)
  7. treadmill
  8. desk elliptical


Don't be afraid to tinker.  Often, there won't be one "perfect" product, or it will be beyond your budget.  Modifying products to suit your needs will often be necessary to get the result you need.

The Chair

The chair is the most talked about part of an ergonomic workstation.  And, for this reason, I won't spend much time on it.  Much writing has already been devoted to the topic, and choosing a chair is very subjective.  Go educate yourself on what to look for in a chair, then find what works for you.

One of the most difficult things about choosing a chair is the fact that you don't know how your body will react to it after days or weeks of sitting in it.  There's a couple ways you could go with this.

Option 1: Go to a store and sit in as many chairs as you can for as long as you can.  This will at least put a few chairs in the "definitely not" category.  You may have to visit a few stores as many of the high end retailers prefer to sell out of their own showrooms.  Or, a store like Design Within Reach may allow you to sample several in one place.

In my case, I don't live in a large city with such showrooms.  So I had to wait until I happened to be in a large city for another reason.  Even in that case, I didn't like the first chair I bought, so I ended up buying a second one...then I went back to the first one because I can't afford a third one.  This can get expensive quickly.  I still haven't found a way around this; if you have a solution, please let me know.  Personally I have "modified my chair" with a seating pad (see below), and it is getting me by.

Option 2: "try before you buy".  Some retailers will let you take chairs and try them at your office for an extended period of time.  If you're fortunate enough to live near a store which has a selection of chairs which interest you and has such a program, take advantage of it.

Note: These options are written in regards to "high end" ergonomic chairs (Herman Miller, Humanscale, etc.)  There are also the cheap options available at your local office supply store, but they lack the adjustability necessary to fit many people.  Many of the cheaper chairs don't even try to be ergonomically healthy.

Again, do some reading on what to look for in a chair before you go shopping.  When do you start shopping, start with the excellent, in-depth reviews from The Wirecutter.  Unlike some of the review sites, they actually buy the products, take them apart, and test them thoroughly in-house.

If you buy a high-end chair, check with  Call them to get a better price than their website.  They have been the cheapest prices I have found on new chairs.  Used chairs can be found on eBay, but you never really know how old the chair is or how well it has been treated.  

Also, beware of Madison Seating (they sell on eBay and on their own website).  They sell refurbished chairs (meaning they take working parts from several broken chairs to make a working one) and have terrible reviews online.

The common high end chairs are the most talked about and offer excellent ergonomics, but there are a couple niche categories which are worth mentioning...

Movement-based seating

As mentioned before, movement is key.  Many chairs provide proper spinal alignment, but don't allow or encourage movement.

The cheap, commonly recommended option is sitting on an exercise ball.  There is lots of discussion on this topic, so I won't dig into it here.  Personally, I've never had luck with the ball.  I inevitably slouch after about 15 minutes, and it seems to put more pressure on my spine.

Side note: If you have trouble with slouching, check out Intelliskin.  A friend of mine had it recommended to him by a prominent physical therapist.  I gave it a shot, and it works pretty well.  Be sure to get the version with a zipper or they are a pain to get on/off.

After watching a few videos by The Ergonomics Guy on YouTube, I have learned that there are other options.  For example: Spinalis Chairs and the Core Chair.  I have not tried any of these chairs yet, but it is something I'm keeping in mind for the future.



Tailbone relief

Recently, I have found a couple products which relieve pressure on the spine by leaving space below the tailbone on the seating surface.  This is possible using a seat cushion like this one, or by buying a chair specifically designed for the purpose.  A quick bit of research found these two companies: Charmichael Throne & Hara Chairs. (see also the Core chair above)

Hara Chair

Carmichael Throne

I opted to start with a seat cushion to save money.  It works well for relieving tailbone pressure, but it does raise my body an inch or two.  This causes my chair's lumbar support to be in the wrong area of my back and my shoulder blades to hit the plastic at the top.  Overall, the benefit outweighs the con, but eventually, I would like a more accommodating chair.

My current seating arrangement

Zero Gravity Chairs

Ok, this one is just for fun.  Check out the Altwork or the even more extreme MWE Lab Emperor!  Way beyond my price range, but very cool looking.



The Desk

A sit-to-stand desk is a must.  This is a desk which can adjust easily from sitting to standing height, either with an electric motor or manual crank handle.

The market has been good to us over the past several years.  There are now many choices, and prices have come down significantly.  As of this writing, you can get a high quality desk under $400.

I won't do a comparison of the various offerings available, because that has already been done by The Wirecutter.  Their top picks make a great choice.  However, after reading their reviews and doing loads of additional research, I went a different route.  I found the Herman Miller Envelop.  It is harder to find, and almost no-one is talking about it...but it is almost perfect, in my opinion.

Here's why I chose it:

  • The top slides forward which helps accommodate under-desk cycling (more on that later).
  • The front of the desk has a body cutout which lets the arms hang naturally at your sides, not extended in front of your body.
  • The front is also slanted and coated in rubber to avoid a hard edge digging into your forearms.  

I have not found any other desks with these features.

Note: The standard Envelop desk is not height adjustable.  Be sure to look for the height-adjustable model.  The link above should take you to the right one.

The desk does have a few downsides:

My Setup
  1. Size

    The desk is the perfect size for someone who works exclusively on their computer.  However, for someone who needs room for lots of paperwork, it may be too small (or, would at least need to be supplemented with another table).  Also, if you use more than two monitors, monitor arms are a must.  The desk is simply not large enough without them.

    Also note, the 
    Herman Miller Flo monitor arms are the only ones I could find which fit this desk.  See the "monitor arms" section below for more detail.
  2. Leg Width

    The legs are close enough that chair wheels often bump them.  Even more importantly, they are too narrow to accommodate many desk treadills.  That said, this downside can be overcome with some effort (more on that later).
  3. Price & Availability

    This desk retails for over $3000!!!  It can occasionally be found cheaper on eBay and is even sold a bit cheaper than retail on Amazon.  That said, if you are looking for a steal, it is tough to find on this desk.  I have seen them as low as $1000 on eBay for the model with a laminate top.  However, that is exceedingly rare.

    Herman Miller is a company whose focus is bulk sales to companies, not individuals.  As a result, there aren't many retailers who carry this desk.
  4. Height memory

    The desk comes with just a standard up/down pushbutton control.  This is not quite as convenient as the memory modules which come on many desks now.  Those have several (usually 4) height presets which the user can trigger with a single button press, rather than holding the up or down button until the desired height is reached (and probably pressing another time or two to fine tune).

    I have found that Herman Miller makes a memory module which fits the Envelop desk.  The part number is U1BC4KN, and it is only available from a Herman Miller dealer.  It is the same memory module available on their Renew desk. 

    I decided not to purchase one for my setup because of the ridiculous $240 price tag.  I guess it should be expected of a Herman Miller product, but I just can't bring myself to pay almost the price of a new desk for the convenience.  That said, I do wonder if it would extend the life of the motor by reducing height "fine tuning".

Even with these minor drawbacks, I still think this desk is head & shoulders above everything else on the market.  If mine broke, I would buy another one tomorrow, or at least, when I could find another deal on one.

Finally, get an anti-fatigue mat.  This isn't optional.  If you're going to stand, get a mat; it will save your joints.  Again, The Wirecutter keeps a recommendation list up to date.

The Treadmill

What? A treadmill?  At your desk?  Yes!  As mentioned before, movement is key.  A treadmill keeps you moving while you work.

Note: It will take about week to get used to walking while working, but it is absolutely worth it.  I personally got dizzy every time I stepped off of it the first few days, but now it doesn't phase me.

There are two routes here: buy a treadmill designed for a desk or modify a treadmill to fit a desk.  I've done both.  When I first looked at treadmills, I decided I couldn't quite handle the $1000+ price tag on a "desk treadmill", and at the time, I didn't want to modify my desk to fit a wider model.  So, when I found this blog post about modifying an existing treadmill which already fit under my desk, I gave it a shot.  I bought the Confidence Power Plus and followed the instructions in that post to turn it into a "desk treadmill".  That is, I removed the bars and just set the control panel on my desk.

Confidence Power Plus

It did the job, but not without drawbacks:

  1. The treadmill motor is woefully undersized.  The belt slows on every step, leading to a halting gait.  I got used to it, but I question its effect on the knees over years of use.
  2. The treadmill has an annoying "feature": It stops every 30 minutes.  It doesn't slow to a stop; it just stops.  The first few times it happens, you'll probably flail to avoid crashing into your desk, but after a while, you intuitively notice the change in motor sound as it loses power and adjust accordingly.
  3. The cord to the control panel is too short to push the treadmill out from under the desk without the control panel crashing to the floor.  This can be remedied by moving the control panel yourself before moving the treadmill or replacing/extending the cord (soldering required).
  4. You cannot stand on the sides of the treadmill; it will tip.  If you are not walking, you must step off completely.  Not a huge deal because it isn't very high.

If you can handle those drawbacks, the treadmill is a decent, inexpensive introduction to walking at a desk.  It is lightweight and can be slid out from under the desk easily.  I added furniture sliders like these to make it easier (on hard floors, felt sliders would work better).

That treadmill lasted almost 4 years of daily use before it started making distracting squeaking noises.  Fortunately, I had purchased the Square Trade warranty on Amazon when I purchased the treadmill because I knew the treadmill was not terribly well made.  I rarely buy "service plans", but this one worked out quite well.  I filed a claim only a few months before the 4 year warranty expired, and they made it very easy.  After they & I were unable to find a treadmill repair company in my city, they simply cut me a check for the full price of the treadmill.  Not a bad deal.

Note: you could also find a used treadmill and modify it.  Most home treadmills are bought with great intentions and barely used.  I went with the above treadmill because it had a small control panel that fit nicely on a desk and the walking surface fit under my narrow desk.

After that treadmill bit the dust, I decided to upgrade to the real deal.  I read the reviews on Work While Walking and purchased the iMovR ThermoTread GT.  I found some casters at my local Home Depot which threaded in perfectly where the feet had been.  These allowed it to be rolled under the desk (it is much heavier than the old one).

I've only been walking on it a week, but so far so good.  Surprisingly, it isn't as "life changing" as I anticipated.  It is certainly better than the cheap one I started with, but the walking experience isn't all that much different.  That said, the controls are nicer, the cord is long enough, it doesn't stop every 30 minutes, and the build quality is far nicer than the old one.  I anticipate it lasting much longer than 4 years.

Modifying My Desk

As mentioned before, my desk legs were too close together to fit a standard size treadmill.  I finally bit the bullet and modified it.  I got a few feet of 1/8" 2"x2" angle iron (steel) and spent some quality time with a grinder shaping it to move each leg out 3 inches and down by 1/2" (which allowed the motor to clear the outside edge of the desk).  After a few mistakes and several hours of effort (my metalworking skills are definitely amateur-level), I came away with some leg brackets I was happy with - which fit the new treadmill.  I still wouldn't trade this desk.  Have I mentioned that I like this thing?

Desk Elliptical

A few years after purchasing my first treadmill, I started to think about ways to incorporate movement while seated.  One way is to sit on a chair which allows, even encourages movement.  See the "Chair" section for more info on that.

Another way is using an under-desk pedaling machine.  They come in two flavors: under-desk "bikes" like the DeskCycle and ellipticals like the Cubii.  After reading a few blog posts on the topic, I decided an elliptical would be less distracting and reduce my chances of knocking my knees on my desk.  After reading reviews from Work While Walking, I decided I liked the Cubii, but I couldn't quite stomach the $350 price tag.  However, as luck would have it, before long they came out with the Cubii Jr.  It is a scaled down version of the Cubii which gets rid of the bluetooth & phone app integration, which at a $100 price difference, I can easily live without.  I found the best deal on QVC ($200 at the time).

Cubii Jr

After a couple months of use, I love it.  It burns a few calories each day and it stimulates circulation in my legs (one of the hazards of sitting).  Well worth it.

It is worth noting that after a few months, the Cubii started making an intermittant squeaking noise, bad enough that it was distracting in a quiet office.  I contacted their support and, after sending in a recording of the noise & a couple other bits of info, I was sent a new unit and a return label for the old one.  At one point, their support person hadn't responded in about a week, and I had to prompt the follow up.  But, other than that, it was pretty painless, so their support & warranty get a thumbs up from me.

The "recline" feature of the Envelop desk has come on quite handy while using the elliptical.  It allows me to raise the desk high enough to clear my knees while still keeping my typing surface at the proper level.

The Mouse

Wrist angle while using the mouse is crucial.  The wrong angle, over years of use, will give you carpal tunnel.  

Notice the hard upward angle on the wrist...carpal tunnel syndrome in the making.

Probably the best solution to this is using a vertical mouse.  I've found that The Human Solution has a nice selection.

This is another area I've opted to go a different route.  I have used a Logitech mouse with "hyper scroll" for years, and I just can't give up that feature.  Essentially, it puts a bearing inside the scroll wheel, and gets rid of the scroll "click".  This allows you to give the scroll wheel one good spin and scroll hundreds of lines through a document at a time.  If you deal with long documents or files on a regular basis, it is a life saver.

Unfortunately, Logitech doesn't make a vertical mouse, and I haven't found any other manufacturers which offer that feature.  So, I opted to keep my mouse and add the Humanscale Mouse Mate.  It attaches with velcro, and after a bit of modification (see cuts to plastic & foam below), it has fixed my wrist angle.

Better angle with the Mouse Mate attached.

The Keyboard

This is another area in which wrist angle is extremely important.

Note the harsh wrist angle (ulnar deviation) with a standard keyboard...Bad!

And the other harsh angle (extension)...also bad.

Years ago, I started to develop wrist pain, and decided to try out a Microsoft Natural 4000.  It worked great, and my wrist pain went away.  I continued using it until mid-2017.  I then began to realize that it put a bad angle on my elbow & shoulder because my mouse hand was well to the right of my body.  This is the result of the number pad included on the right side of the keyboard.

For that reason, I decided to get a keyboard without a number pad.  However, I use the number pad on a daily basis, so I purchased a standalone number pad as well.

The cheapest option as of this writing is the Microsoft Sculpt.  It is essentially the same keyboard as the Microsoft Natural 4000, but it separates the number pad, allowing it to be placed elsewhere on the desk.  The downside, and the reason I didn't buy one, is the "chiclet"-style keys.  However, if that isn't an issue for you, this is the best back for your buck currently.

The Microsoft Sculpt
Note: many people don't like the mouse that comes with the combo.  You can also buy the keyboard separately.

Personally, I decided on the Matias Ergo Pro. It has mechanical keys (which I prefer because of the feel) and a standard layout (so I didn't have to relearn finger movements).  In order to get both tent & negative tilt, I had to use a couple of these: miggo Splat SLR Mini Tripod.  I bent them in such a way that they maintained contact all the way to the edge of the keyboard halves.  This gave me a very stable result.

Wrist angle straight because of negative tilt on the keyboard

Wrist angle straight because of keyboard tenting & angle (bottom spread apart)

Finally, because the keyboard didn't come with one, I chose the Cherry G84-4700LUCUS-2 Keypad for my number pad.  Again, it has mechanical keys, so the feel is great.  The ergonomic angles are not ideal, but I don't spend a lot of time using the number pad.  If I did, I would need to find a way to improve its ergonomics.


I run 24" monitors with a fairly large text size.  This helps avoid the urge to lean forward while reading.  I would buy 27" monitors if I were shopping now.  They are currently the best bang for the buck.

Also, most people using two monitors put them each at an angle with the border directly in front of them.  I encourage you to put one monitor squarely in front of you, and the other to one side.  This will allow you to keep your neck straight while focusing on your primary monitor.

Also, come up with a way to remind yourself to refocus your eyes regularly on something in the distance - important for eye health.  I personally make sure my desk always faces a window.  This allows things to catch my eye occasionally.

Monitor Arms

The Herman Miller Flo monitor arms are also seldom talked about, but a very solid option.  I bought them because they are the only arms compatible with the Envelop desk, but they could be a good choice for anyone.  The use a spring internally rather than a gas cylinder, so they won't give out after a few years of use.

I bought mine from  Calling them will likely get you a better price than their website.


Take time to think about your posture, your wrist position, your eye health, and your level of movement.  Make the adjustments to your routine and your workspace which will keep you healthy.  When you decide to buy a product, do your research.  The right one for you might not be the one everyone else talks about.

Tuesday, May 12, 2015

Multi-line text replacement with Powershell

A number of times recently I have had need of a script to replace a chunk of code or XML in a few dozen files. I've been enjoying Powershell lately; so I decided to use it to write the script. A couple challenges presented. First, the text replacement had to handle line breaks. Second, it had to handle (escape) special characters. It took me a couple hours and tips from a few different blog posts & Stack Overflow questions to get it right. So, I'll post the product here.

$oldCode = @"
/// <summary>
        /// My Old XML Comment
        /// </summary>
        public static new string ThingID

$newCode = @"
/// <summary>
        /// My New XML Comment
        /// </summary>
        public new const string ThingID = 

Get-ChildItem .\ -Recurse –Include “*.YourFileExtension” | foreach-object {
    $text = Get-Content $_.Fullname -Raw
    $text = $text -replace $oldCode, $newCode
    $text | Out-File $_.Fullname -Force utf8

Obviously I've simplified my script a bit, but the above script should be completely functional. Notice that you can essentially just paste in your find & replace text. No special work to do in escaping characters. These two posts were especially helpful in getting this result:

Thursday, March 19, 2015

Powershell script to remove Visual Source Safe References

I am migrating a codebase from Visual Source Safe (yes, in 2015, still VSS) to Git. One issue is the pesky way in which VSS embeds references to itself all over the place. Brian Carroll has a nice list of the things that need to be deleted here.

The project I'm working on has dozens of solution & project files spread through a large folder hierarchy, and I really didn't want to edit each file by hand. So, I wrote the following Powershell script. This was tested using Powershell 3.0 and should work for any project.  Only the $rootFolder value would need to be changed or converted into a script parameter.

$rootFolder = "C:\Projects\Workspace\KillVSSTest"

Get-ChildItem $rootFolder -Recurse -File | Set-ItemProperty -Name IsReadOnly -value $false

Get-ChildItem $rootFolder -include *.scc, *.vssscc, *.vspscc -Recurse | Remove-Item  -Force

Function RemoveTextInclusive($beginningText, $endingText, $includeFiles) {
    Get-ChildItem $rootFolder -include $includeFiles -Recurse | ForEach-Object {
        $text = [IO.File]::ReadAllText($_.FullName)
        $text = $text -replace "$beginningText(.|\n)*?$endingText", ""
        $text | Out-File $_.FullName -Force utf8

RemoveTextInclusive "\s*GlobalSection\(SourceCodeControl\)" "EndGlobalSection" @("*.sln")
RemoveTextInclusive "\s*\" "\<\/SccProjectName\>" @("*.vcxproj","*.csproj","*.vbproj")
RemoveTextInclusive "\s*\" "\<\/SccAuxPath\>" @("*.vcxproj","*.csproj","*.vbproj")
RemoveTextInclusive "\s*\" "\<\/SccLocalPath\>" @("*.vcxproj","*.csproj","*.vbproj")
RemoveTextInclusive "\s*\" "\<\/SccProvider\>" @("*.vcxproj","*.csproj","*.vbproj")

Wednesday, October 29, 2014

Windows can't find Samsung SSD

Yesterday, I got a new Samsung 840 EVO SSD to replace the slow hard drive in my Dell laptop.  I dutifully backed up my old drive and popped in the new SSD to restore it.  Windows, however did not show the drive in the "Computer" area.  Long story short...I simply had to open the Disk Management utility (Start > Right click "Manage" > Disk Management).  It immediately prompted me to format the MBR on the SSD.  Once I did, all went smoothly.

I should note that I did not use the included Samsung Data Migration software.  I started to, but the data copy was going to take 10 hours; so, I stopped it.  I used Acronis TrueImage instead, which took only a couple hours.  Perhaps if I had used the manufacturer's software, I wouldn't have had an issue.

Tuesday, August 19, 2014

Window snap to quarter screen

The other day, I was playing with Linux Mint, and I realized that it would respond to Windows hotkey commands to "snap" windows to half of the monitor.  However, would also allow me to snap into a corner (a quarter of the screen) or to the top or bottom half of the screen - two things Windows does not do.  As a friend commented, "Linux does Windows better than Windows does Windows.

I've wanted this funtionality before, but I had never gone looking for an add-on to do it.  Today I found an excellent solution - WindowPadX.  It is open source (free for personal & commercial) and very lightweight.  It allows you to use the Win key + a number on the number pad to perform all of the functions mentioned above.

The documentation is non-existent, but I managed to get it running with relatively little trouble.  Here's what I did:

  1. Install AutoHotkey.  Yes, it requires a separate piece of software to run :(.  However, this is one that I've been wanting to play with for a while anyway, so it wasn't a big deal.  AutoHotkey is very lightweight, and they even have a portable version which makes me happy (more details on that below).
  2. Browse to the WindowPadX page on GitHub.  Find the "Download zip" button on the right-hand side near the bottom.  Download & unzip on your computer
  3. Open the unzipped folder and run the WindowPadX.ahk file inside.  This will launch WindowPadX which will run in the background with an icon in the system tray.
  4. Start using it.  You should now be able to press the WIN key + any number key on the number pad to move the window around your screen(s).  Here's what I've found through experimentation:
  • WIN + 2, 4, 6, or 8 will snap the window to half of the screen (bottom, left, right, or top respectively).  Pressing the number twice will snap the window to a quarter of the screen vertically or horizontally.
  • WIN + 1, 3, 7, or 9 will snap the window into a corner taking a quarter of the screen (half width, half height.  Pressing the number twice will snap the window to an eighth of the screen.
  • WIN + up arrow or down arrow will still maximize and minimize the window respectively.
If you want the program to run automatically when you start the computer, you can put a shortcut to WindowPadX.ahk in your startup folder.  You can find the startup folder here: C:\Users\YOURUSERNAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup.  Alternatively, you can open your start menu, find the startup folder, right click, and select "open".

To run WindowPadX with AutoHotkey portable.  You'll need to tell Windows what program to use to open .ahk files.  You can simply open the WindowPadX.ahk file, chose "Select a program from a list of installed programs", and put in the path to the AutoHotkey.exe.  Alternatively, you can use a portable file extension program like Coffee to make things truly portable.

Monday, August 11, 2014

SQL command works from Management Studio but not command line (SqlCmd)

SQL Server has a command line component which allows users to run SQL commands directly or in files from the command line.  The command is sqlcmd (or Invoke-SqlCmd for Powershell).

I recently ran into a situation in which my commands would run just fine in SQL Server Management Studio, but failed from the command line.  Specifically, I was running a series of SQL commands stored in files.  I would run the files one after another.

What I found is that some of the files were missing the "USE [DatabaseName]" directive.  So, when those files ran, they were not targeting the correct database.  These worked in Management Studio however, because the earlier scripts had the directive, and Management Studio holds onto that setting.  That is, once a script sets the target database, it will use that database until instructed otherwise.  The command line tools do not do this.