Giter Site home page Giter Site logo

cmd-multiple-commands-from-under-csharp's Introduction

CMD multiple commands from under C#

The solution emulates working with the CMD console.
Gather all your CMD-commands you want to type on the console and invoke them from you C# code.

I use this approach to execute a bunch of multiple CMD commands and batch files.

Implementation CmdShell.cs. Sample usage Program.cs.

Warning

For any invocations without an iteractive session (build machines, windows services)!
Use the ExecAndShowCatched method instead of ExecAndShow. ExecAndShow doesn't work in this case.

C# Example

    var cmdCommands = $@"
CD /

CALL none_existing_command /oops

ping example.com -n 5

CALL MsBuild SomeProject.csproj^
 /target:Build^
 /p:Configuration=Release^
 /verbosity:normal^
 /maxCpuCount

ECHO ErrorLever = %ERRORLEVEL%
";

    //new CmdShell().ExecAndShowCatched(cmdCommands);
    new CmdShell().ExecAndShow(cmdCommands);

Useful to know

  • Use ExecAndShowCatched method if you need to intercept CMD outputs in your C#. You can store or analyze it.
  • ExecAndShow method allows to debug in an interactive session, i.e. where you can see a console window.
  • I put all logic and methods to a single file for an usefulness of automation professionals. Feel free to decompose it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.