Click here to Skip to main content
15,885,278 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to get a list of all the APIs exposed by a web service? Pin
Ray Cassick3-Feb-11 5:39
Ray Cassick3-Feb-11 5:39 
QuestionProblem with multirow selection in DataGridView control Pin
sandeepkavade2-Feb-11 22:14
sandeepkavade2-Feb-11 22:14 
QuestionHow to run a Command and retrieve data from it ? Pin
All Time Programming2-Feb-11 21:01
All Time Programming2-Feb-11 21:01 
AnswerRe: How to run a Command and retrieve data from it ? Pin
Richard MacCutchan2-Feb-11 21:58
mveRichard MacCutchan2-Feb-11 21:58 
GeneralRe: How to run a Command and retrieve data from it ? Pin
All Time Programming2-Feb-11 22:38
All Time Programming2-Feb-11 22:38 
AnswerRe: How to run a Command and retrieve data from it ? Pin
Pravin Patil, Mumbai2-Feb-11 22:17
Pravin Patil, Mumbai2-Feb-11 22:17 
AnswerRe: How to run a Command and retrieve data from it ? Pin
OriginalGriff3-Feb-11 0:00
mveOriginalGriff3-Feb-11 0:00 
GeneralRe: How to run a Command and retrieve data from it ? Pin
All Time Programming3-Feb-11 1:02
All Time Programming3-Feb-11 1:02 
Thanks OriginalGriff,

I coded the foloowing :
<code>
processInfo = new ProcessStartInfo("cmd.exe", "/C " + command);
sb = new StringBuilder();
processInfo.UseShellExecute = false;
processInfo.RedirectStandardOutput = true;
processInfo.CreateNoWindow = true;
process = Process.Start(processInfo);

process.BeginOutputReadLine();
process.OutputDataReceived += new DataReceivedEventHandler(Process_OutputDataReceived);

public string ErrorMessage
{
get { return errorMsg; }
set { errorMsg = value; }
}

private void Process_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
errorMsg = "";
connected = false;
string d = e.Data;

if (!string.IsNullOrEmpty(d))
{
if (sb != null)
sb.Append(d + "\n");
Console.WriteLine("LINE = " + d); // I see each line
if (d.IndexOf("Initialization Completed") &gt; 0)
{
connected = true;
Console.WriteLine("********* Connected = " + connected);
}
else if (isInValidLine(d))
{
//throw new Exception(d);
connected = false;
errorMsg = d;
return;
}
}
}
private bool isInValidLine(string line)
{
if (line.IndexOf("Cannot load file") &gt; 0)
{
errorMsg = line;
return true;
}
return false;
}
</code>

The output that I see is :
LINE = Thu Feb 03 17:22:28 2011 Cannot load file path (null) (SSL_CTX_load_verify_locations): error:02001002:system library:fopen:No such file or directory: error:2006D080:BIO routines:BIO_new_file:no such file: error:0B084002:

Based on the above code and output, isInValidLine() should find the text "Cannot load file" and errorMsg should be set to the line and it should return true.

My Implementation :
<pre>
while (!oc.Connected)
{
timepassed = (int)(DateTime.Now - start).TotalMilliseconds;
if (timepassed &gt; timeout)
{
oc.DisconnectServer();
connectedToVpn = false;
throw new Exception("NotConnectedException");
} else if (oc.ErrorMessage.Length &gt; 0)
{
oc.DisconnectServer();
connectedToVpn = false;
throw new Exception(oc.ErrorMessage);
}
Thread.Sleep(100);
}
</pre>

checks for if (oc.ErrorMessage.Length &amp;gt; 0), but the value of errorMsg is always "". Why so ?

Where am I going wrong or doing something invalid that the code seems to never check for isInvalid() method only ? I tried adding the same lines of isinvalid() in the place it is called, but yet no differnce.

Where am I going wrong that the Process_OutputDataReceived never sets and errorMsg via isInvalid() ? Please help me get my mistake and rectify it. Badly stuck up at this location.


Thanks & Regards,


GeneralRe: How to run a Command and retrieve data from it ? Pin
OriginalGriff3-Feb-11 1:11
mveOriginalGriff3-Feb-11 1:11 
GeneralRe: How to run a Command and retrieve data from it ? Pin
All Time Programming3-Feb-11 1:24
All Time Programming3-Feb-11 1:24 
GeneralRe: How to run a Command and retrieve data from it ? Pin
OriginalGriff3-Feb-11 1:30
mveOriginalGriff3-Feb-11 1:30 
GeneralRe: How to run a Command and retrieve data from it ? Pin
All Time Programming3-Feb-11 2:02
All Time Programming3-Feb-11 2:02 
GeneralRe: How to run a Command and retrieve data from it ? Pin
OriginalGriff3-Feb-11 2:30
mveOriginalGriff3-Feb-11 2:30 
GeneralRe: How to run a Command and retrieve data from it ? Pin
All Time Programming3-Feb-11 2:49
All Time Programming3-Feb-11 2:49 
GeneralRe: How to run a Command and retrieve data from it ? Pin
OriginalGriff3-Feb-11 3:01
mveOriginalGriff3-Feb-11 3:01 
GeneralRe: How to run a Command and retrieve data from it ? Pin
All Time Programming3-Feb-11 3:17
All Time Programming3-Feb-11 3:17 
GeneralRe: How to run a Command and retrieve data from it ? Pin
All Time Programming3-Feb-11 2:56
All Time Programming3-Feb-11 2:56 
GeneralRe: How to run a Command and retrieve data from it ? Pin
OriginalGriff3-Feb-11 3:06
mveOriginalGriff3-Feb-11 3:06 
GeneralRe: How to run a Command and retrieve data from it ? [modified] Pin
All Time Programming3-Feb-11 3:27
All Time Programming3-Feb-11 3:27 
AnswerRe: How to run a Command and retrieve data from it ? Pin
PIEBALDconsult3-Feb-11 1:44
mvePIEBALDconsult3-Feb-11 1:44 
QuestionPrint Settings for ReportViewer pogrammatically Pin
freshonlineMax2-Feb-11 18:24
freshonlineMax2-Feb-11 18:24 
GeneralRe: Print Settings for ReportViewer pogrammatically Pin
Praveen Raghuvanshi2-Feb-11 19:07
professionalPraveen Raghuvanshi2-Feb-11 19:07 
GeneralRe: Print Settings for ReportViewer pogrammatically Pin
freshonlineMax2-Feb-11 19:46
freshonlineMax2-Feb-11 19:46 
Question[Solved] Drag'N'Drop to and on control [modified] Pin
lukeer2-Feb-11 4:04
lukeer2-Feb-11 4:04 
AnswerRe: Drag'N'Drop to and on control Pin
Henry Minute2-Feb-11 9:25
Henry Minute2-Feb-11 9:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.