using System;
namespace StartWithAffinity
{
class Program
{
static int Main(string[] args)
{
if((args.Length > 3) || (args.Length < 1))
{
Console.WriteLine(@">StartWithAffinity ""Filename.exe"" AffinityMask ""Params""");
return 1;
}
//Check file name
string mFileName = args[0];
if(!System.IO.File.Exists(mFileName))
{
Console.WriteLine("The provided exe file does not exists");
return 2;
}
//check optional mask
string mMaskString = (args.Length == 2) ? args[1] : "1";
int mMask;
try
{
mMask = Convert.ToInt32(mMaskString);
}
catch
{
Console.WriteLine("Bad mask: provide an int32 number");
return 3;
}
//check optional arguments
string mArguments = (args.Length == 3) ? args[2] : "";
//Run the process
try
{
System.Diagnostics.Process mProc = new System.Diagnostics.Process();
mProc.StartInfo.FileName = mFileName;
mProc.StartInfo.Arguments = mArguments;
mProc.Start();
mProc.ProcessorAffinity = (IntPtr)mMask;
if(mArguments != "")
{
mProc.WaitForExit();
return mProc.ExitCode;
}
else
return 0;
}
catch(Exception e)
{
Console.WriteLine(e);
return 1000;
}
}
}
}