How To Call Python Script X++ D365fo
static void CallPythonScript(Args _args) { str command, output; InteropPermission perm; System.Diagnostics.ProcessStartInfo processStartInfo; System.Diagnostics.Process process; ; // Update the command with the correct path to the Python script and include the data to be passed command = @"python ""C:\Users\AxAdmin\AxWhatsAppTA.py"" ; // Set up security permission for external process execution perm = new InteropPermission(InteropKind::ShellExecute); perm.assert(); // Initialize the process start info processStartInfo = new System.Diagnostics.ProcessStartInfo("cmd.exe", "/c " + command); processStartInfo.set_UseShellExecute(false); processStartInfo.set_RedirectStandardOutput(true); processStartInfo.set_CreateNoWindow(true); // Start the process process = new System.Diagnostics.Process(); process.set_StartInfo(processStartInfo); process.Start(); output = process.get_StandardOutput().ReadToEnd(); process.WaitForExit(); // Revert assert CodeAccessPermission::revertAssert(); // Optionally, handle the output info(strFmt("Output: %1", output)); }
This Code Written By Mohamed Elsagher
Comments
Post a Comment