Aklımda Kalası Kelimeler

* давайте работать вместе
* Zarf ve Mazruf, Zerafet(xHoyratlık) ile aynı kökten(za-ra-fe) gelir
* Bedesten
* Suç subuta ermiştir - Suç sabit olmuştur

23 Ocak 2012 Pazartesi

C# ile Process çağırma

Ref: www.jonasjohn.de

// This snippet needs the "System.Diagnostics" library
 
// Application path and command line arguments
string ApplicationPath = "C:\\example.exe";
string ApplicationArguments = "-c -x";
 
// Create a new process object
Process ProcessObj = new Process();
 
// StartInfo contains the startup information of the new process
ProcessObj.StartInfo.FileName = ApplicationPath;
ProcessObj.StartInfo.Arguments = ApplicationArguments;
 
// These two optional flags ensure that no DOS window appears
ProcessObj.StartInfo.UseShellExecute = false;
ProcessObj.StartInfo.CreateNoWindow = true;
 
// If this option is set the DOS window appears again :-/
// ProcessObj.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
 
// This ensures that you get the output from the DOS application
ProcessObj.StartInfo.RedirectStandardOutput = true;
 
// Start the process
ProcessObj.Start();
 
// Wait that the process exits
ProcessObj.WaitForExit();
 
// Now read the output of the DOS application
string Result = ProcessObj.StandardOutput.ReadToEnd();

ARP dos komutundan verileri okumak

Ref: http://mostthingsweb.com


class Program
{
    static void Main(string[] args)
    {
        string sIp = "10.214.36.245";
        var arpStream = ExecuteCommandLine("arp", "-a " + sIp);

        // Consume first three lines
        for (int i = 0; i < 3; i++)
        {
            var s = arpStream.ReadLine();
        }

        // Read entries
        while (!arpStream.EndOfStream)
        {
            var line = arpStream.ReadLine().Trim();
            while (line.Contains("  "))
            {
                line = line.Replace("  ", " ");
            }
            var parts = line.Split(' ');
            string sMacAdresi = parts[1].Replace("-", "").ToUpper().Trim();
        }
    }


    public static StreamReader ExecuteCommandLine(String file, String arguments = "")
    {
        ProcessStartInfo startInfo = new ProcessStartInfo();
        startInfo.CreateNoWindow = true;
        startInfo.WindowStyle = ProcessWindowStyle.Hidden;
        startInfo.UseShellExecute = false;
        startInfo.RedirectStandardOutput = true;
        startInfo.FileName = file;
        startInfo.Arguments = arguments;

        Process process = Process.Start(startInfo);

        return process.StandardOutput;
    }
}

Hiç yorum yok: