Hi,
I try to launch a Windows .bat file from an automation script. I found an example below on Internet but it doesn't work from the automation script.
Do you have any any how to launch a .bat in silent mode ?
using System;
using System.Diagnostics;
using Skyline.DataMiner.Automation;
public class Script
{
public void Run(Engine engine)
{
string batch = @"C:\Skyline DataMiner\Documents\DMA_COMMON_DOCUMENTS\myscript.bat";
string parameters = $"/c \"{batch}\"";
Process.Start(<span class="hljs-string">@"C:\windows\system32\cmd.exe"</span>
, parameters);
}
}
Hi Berard,
The problem could be the usage of \ in the command arguments. Maybe try something like this:
var startInfo = new ProcessStartInfo
{
WorkingDirectory = @"C:\Skyline DataMiner\Documents\DMA_COMMON_DOCUMENTS",
FileName = @"C:\Windows\System32\cmd.exe",
Arguments = @"/c ""myscript.bat""",
CreateNoWindow = true,
};Process.Start(startInfo);
Another option is to escape the command line arguments: https://stackoverflow.com/questions/5510343/escape-command-line-arguments-in-c-sharp
It works fine, Thanks a lot Tom