473,395 Members | 1,675 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Why is my Process redirect stdoutput is returning different number

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.
Aug 9 '07 #1
0 1278

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Peter Åstrand | last post by:
There's a new PEP available: PEP 324: popen5 - New POSIX process module A copy is included below. Comments are appreciated. ---- PEP: 324 Title: popen5 - New POSIX process module
0
by: Guy | last post by:
Hi, I created a function, which seems to work, quite well, it tells me if a process is running in widows using the pid number (I'm aware that the pid number in widows is not called a pid and this...
4
by: Michael Trosen | last post by:
Hi Everyone, I hope someone can help, I'm pretty new to pro*c programming. I have the following application setup: a pro*c program calls a stored procedure and recieves a cursor back: the...
5
by: MN | last post by:
Hello all - I'm hoping someone will be able to share their knowledge with me about this issue I'm having because I have run out of answers. Here's the scenario.... I have a .aspx page that...
2
by: Peter McEvoy | last post by:
Folks, I've been building a Webservice API for a contract that will be exposed to the internet at large. There are two endpoints, and each endpoint contains a number of webmethods. Every...
5
by: leo | last post by:
babelfish provides online translation service if clicking one of my links containing: http://babelfish.altavista.com/babelfish/trurl_pagecontent?lp=en_ja&trurl=http://mypage.show.php all the...
1
by: =?Utf-8?B?Q3JhaWc=?= | last post by:
Hi Guys, I am trying to caputre the output for an external application. The idea is to use the System.Diagnostics.Process to run the exe in a process and redirect the output to a string. When...
1
by: Bhavin | last post by:
HI, I have to implement a program using exec command to illustrate concurrent and sequential process. What I did is just create two input file Alpha.txt ======== abcdefghijklmnopqrstuvwxyz...
1
by: gnawz | last post by:
Hi guys, I have a couple of php files that perform various tasks. I will use fields in my system and provide code as well I need help as follows: My database contains the fields Category...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.