Delen via


How to execute an external process from a batch

You might need to execute an external process in a batch and you’re thinking about using WinApi::shellExecute() method. Unfortunately the whole WinApi class is set to run on client. Also the method WinApi::shellExecute() is marked as client method. That why you can’t use this method to execute an external process from batch. How to execute external process then? One option is to use System.Diagnostics.Process .NET class. Here’s a short sample how to use System.Diagnostics.Process to execute an external process:

 {
    System.Diagnostics.Process              process;
    System.Diagnostics.ProcessStartInfo     processStartInfo;
    ;

    new InteropPermission(InteropKind::ClrInterop).assert();

    process = new System.Diagnostics.Process();

    processStartInfo = new System.Diagnostics.ProcessStartInfo();
    processStartInfo.set_FileName("C:\\temp\\test.bat");
    processStartInfo.set_Arguments("Value1 Value2 Value3");

    process.set_StartInfo(processStartInfo);

    process.Start();

    process.WaitForExit();

    info("Finished");
}

Martin F

Comments

  • Anonymous
    April 22, 2009
    The comment has been removed

  • Anonymous
    July 07, 2011
    Thanks very very very ....much !

  • Anonymous
    December 18, 2011
    Great work. Thanks for sharing.