728x90 AdSpace

  • Latest News

    Thursday 30 November 2017

    [Tips] How to Run another Command Line Integrated into Ourself Command Line



    If you have an application which calls another process in a command window and that process has updating stats that output to the console window. That mean you have to inject another console program to your console program!

    How do you can do it?

    - In C# language, we have one API which is Process API. we can use it to call the process and mount into your console program


    How to Run another Command Line Integrated into Ourself Command Line









    Source Code

    static void Main(string[] args)
    {
    // get your exeFileName;
    string exeFileName = Path.Combine(Path.GetTempPath(), "abc.exe");

    Process process = new Process();
    process.StartInfo.FileName = exeFileName;
    process.StartInfo.Arguments = args[0] + " " + args[1];
    process.StartInfo.UseShellExecute = false;

    process.StartInfo.RedirectStandardOutput = true;
    process.StartInfo.RedirectStandardError = true;

    process.OutputDataReceived += Process_OutputDataReceived;
    process.ErrorDataReceived += Process_ErrorDataReceived;

    process.Start();
    process.BeginOutputReadLine();
    process.BeginErrorReadLine();
    }

    private static void Process_ErrorDataReceived(object sender,
    DataReceivedEventArgs e)
    {
    Console.WriteLine(e.Data); // write to ourself console program
    }

    private static void Process_OutputDataReceived(object sender,
    DataReceivedEventArgs e)
    {
    Console.WriteLine(e.Data); // write to ourself console program
    }


    If you have any questions, leave your comment and we can discuss about it!
    Zidane
    • Blogger Comments
    • Facebook Comments

    0 comments:

    Post a Comment

    Item Reviewed: [Tips] How to Run another Command Line Integrated into Ourself Command Line Rating: 5 Reviewed By: Unknown
    Scroll to Top