Many times we execute code that behaves differently when running batch. This often may force us to change the code and use other classes.
I will detail the issues of running the ShellExecute method of class Winapi. The code hadto download data from external table in other on AX:
Public void ImportCustInvoiceTable()
{
InteropPermission perm = new InteropPermission( InteropKind::ClrInterop );
str _str;
;
perm.assert();
_str = curExt();
winapi::shellExecute(“InsertCustInvoice.exe',curExt());
}
I resolved the problem using the classes System.Diagnostics.Process and System.Diagnostics.ProcessStartInfo.
The result was:
server static void ImportCustInvoiceTableForBatch()
{
System.Diagnostics.Process process;
System.Diagnostics.ProcessStartInfo processStartInfo;
Boolean start;
FileName _fileName
;
// Assert CLRInterop permission
new InteropPermission(InteropKind::ClrInterop).assert();
_fileName = “InsertCustInvoice.exe';
//Se instancia ProcessStartInfo en el que se pasa la ruta del ejecutable y los parámetros necesarios
processStartInfo = new System.Diagnostics.ProcessStartInfo(_fileName,curExt());
// Se instancia la clase Process
process = new System.Diagnostics.Process();
// Use the system shell to execute the process
processStartInfo.set_UseShellExecute(false);
// Attach the starting information to the process
process.set_StartInfo(processStartInfo);
// Start the process and wait for it to complete
start = process.Start();
process.Close();
CodeAccessPermission::revertAssert();
}
I hope you find it useful