Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ping commaod from .net

Status
Not open for further replies.

raghu3

Programmer
Dec 19, 2005
96
US
This simple function/class does not compile:

public string getDC()
{
string retVal = "";
System.Diagnostics.Process pe = new Process();
for(int i=0 ; i<MAX; i++)
{
try
{
pe.Start("C:\\I386\\ping.exe ", IPaddr); // ***ERROR LINE ***//
}
catch (Exception e) {
Console.WriteLine("Error in ping:" + IPaddr + ":" + e.Message) ;
}

}// FOR //

return retVal;
}


The error messafew on compile is:

Static member 'System.Diagnostics.Process.Start(string, string)' cannot be accessed with an instance reference; qualify it with a type name instead
The type or namespace name 'pe' could not be found (are you missing a using directive or an assembly reference?)

IF I replace the error line with:

Process.Start("C:\\I386\\ping.exe ", IPaddr);

It works amd compiles, BUT I cannto trap the return code Eg: I have an array of URLs some are dully Ip addresses and there is no way I can trap the return value of the ping: invalid IP does not get into the catch Part.

How to get this working ?








 
You're right that Start() is a static (i.e. class) method so can only be called by the class itself, but I can't see any reason why you can't access your variable IPaddr. It looks like this is an instance variable so should always be available to methods. Could there be a problem elsewhere that means this variable is never being populated or something? It wouldn't make sense for it to be available to the try block but not the catch block...

Tom
emo_big_smile.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top