Other than capturing STDOUT and STDERR, and doing potentially interesting things with them (when the dos PIPE commands work just fine too), I can see no reason to go through the trouble of writing a C# app that is simply shelling out to cmd.exe anyway! About 20 seconds (on a slow day) at the command line, to type:
COPY CON backup.bat
sqlcmd", @" -S .\sqlexpress -i C:\backup.sql
[Ctrl-Z][Enter] to save the file, voila. You can launch the shortcut on the desktop manually, put it somewhere 'safe' and create an "at" command to run it at intervals, etc.
Compare that to launching Visual Studio, creating a console app, adding the needed using statement creating an Object, setting many properties, only to finally call a method that then calls "cmd.exe [whatever you passed in as application path and parameters].
Perhaps I am being naive and missing something here? This is is an excellent example of calling any "command line" from within a C# program, but I fail to see what advantages it gives to a DBA, unless they are hand-writing their own DB maintenance application logic, which is not something I would attempt unless I had a compelling business case not covered by existing functionality.
Why would someone do this rather than using SQL Server maintenance plans, which are very robust and can perform all the needed steps, and email and/or page operators and/or perform other complex chains of actions in the event of success or failure of a job or step of a job?
No offense intended to the OP, I do not mean to come off as sarcastic. This is just my humble opinion. I truly don't understand how this might be of use in a real-world scenario? (I think all blog posts should include this, unless they are intended to be scientific/theory in the first place.)
I understand by using SMO you can pull off some cool stuff; I just haven't come across a scenario that warrants that level of development... Perhaps the projects I work on are all too small? (In the DBs I work with, the biggest tables have a few million rows (that have 1-to-many FK relationships)).
Please excuse my ignorance, and educate a poor fellow!!