Shell Execute with output
Using the System.Diagnostics.Process class you can get a stream to read the output of the application you are executing. For example, you could execute "dir" to list get the directory contents of the working directory specified as a string.
Here's a basic class I wrote that allows you to get the standard output:using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
namespace Kahnadex{
class WindowsHelper{
public static Exception ShellExecute(string in_WorkingDirectory,string in_FileName,string in_Args,out string out_StdOut){
Process p = new System.Diagnostics.Process();
p.StartInfo.WorkingDirectory = in_WorkingDirectory;
p.StartInfo.FileName = in_FileName;
p.StartInfo.Verb = "open";
p.StartInfo.Arguments = in_Args;
//required to capture standard output
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.Start();
p.WaitForExit();
//read the command line output
try{
StreamReader sr = p.StandardOutput;
out_StdOut = sr.ReadToEnd();
return(null);
}catch(Exception ex){
out_StdOut = "";
return(ex);
}
}
}
}
posted by Brian at 7/31/2008 01:03:00 AM | 0 Comments
ToString for C++ base types
#include <sstream>
template <class T>
inline std::string ToString (const T& t){
std::stringstream ss;
ss << t;
return(ss.str());
}
Labels: C++
posted by Brian at 7/31/2008 12:36:00 AM | 0 Comments
Creating or moving a MySQL database
Unlike SQL Server, you cannot reliably move a MySQL database by moving the binary files in the MySQL directory. Instead, you should use the mysqldump utility.
Open a command line window to the MySQL bin directory and make sure both mysql and mysqldump binaries are both present. On Linux this location is likely /usr/local/mysql/bin and on Windows this is most likely C:\Program Files\MySQL\MySQL Server 5.0\
Dump the database using a command like this:./mysqldump --user=user --password=pw database_name_here > db.sql
Then connect using the MySQL command line client and create the database:./mysql --user=user --password=pw
create database new_database_name
use new_database_name
source db.sql
posted by Brian at 7/16/2008 02:36:00 PM | 0 Comments