I have been looking around for a way to execute a bat file from my x++ code.
I have tried this approach , but when my code gets to process.Start()
, nothing further happens.
Using the WINApi::Shellexecute()
is not a possibility for me as i need this to run in batch. Here is the code I'm currently working with:
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\testbat.bat');
process.set_StartInfo(processStartInfo);
process.Start();
process.WaitForExit();
process.Close();
info('Done');
Use System.Diagnostics.Process from .Net;
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\\testbat.bat");
//processStartInfo.set_Arguments("Value1 Value2 Value3");
process.set_StartInfo(processStartInfo);
process.Start();
process.WaitForExit();
info("Finished");
Reference;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.