I Have the following in my own library project and I call it from my C#
application twice each time to get Unix group account information and user
account information. But it would return different number of records (lines
of data read), sometimes 0 records without any of my message, and there
doesn't seem to be a pattern to be found. Can someone have a look and see if
any of my code could possbly cause this? Thanks.
static System.Text.StringBuilder sb = new System.Text.StringBuilder();
static void proc_OutputDataReceived(object sender,
DataReceivedEventArgs e)
{
if(sb.Length 0)
sb.Append("\n");
sb.Append(e.Data);
}
public static int GetNisFile(string parm, ref DataTable dtAccounts,
ref ToolStripStatusLabel slMain, ref StatusStrip ssMain, string
userOrGroup)
{
string accountFile = "", error="";
int numOfAccounts = 0;
System.Diagnostics.Process listFiles = new Process();
sb.Remove(0, sb.Length);
try
{
listFiles.OutputDataReceived += new
DataReceivedEventHandler(proc_OutputDataReceived);
listFiles.StartInfo = new
ProcessStartInfo(Application.StartupPath +
"\\ypcat.exe", parm);
listFiles.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
listFiles.StartInfo.UseShellExecute = false;
listFiles.StartInfo.RedirectStandardOutput = true;
listFiles.StartInfo.RedirectStandardError = true;
listFiles.StartInfo.CreateNoWindow = true;
if (listFiles.Start())
{
listFiles.BeginOutputReadLine();
listFiles.WaitForExit(30000);
if (listFiles.HasExited)
{
error = listFiles.StandardError.ReadToEnd();
if (error == "")
{
accountFile = sb.ToString();
if (accountFile != null && accountFile != "")
numOfAccounts =
CPAUnix.ParseAndInsertAccounts(accountFile,
ref dtAccounts, ref slMain, ref ssMain,
userOrGroup);
}
else
MessageBox.Show(error, "PowerADvantage");
}
else
MessageBox.Show("Time out retrieving NIS " +
userOrGroup + " accounts.",
"PowerADvantage");
}
else
MessageBox.Show("Error starting process to read file.",
"PowerADvantage");
if (listFiles != null)
{
listFiles.CancelOutputRead();
listFiles.Close();
}
return numOfAccounts;
}
catch (Win32Exception wex)
{
MessageBox.Show(wex.Message, "PowerADvantage");
return numOfAccounts;
}
}
--
Thanks.