Running Batch files using Python

Dear Team,

I have a pipeline of Python scripts that run in a sequence that has automated the process of downloading raw files from the exchange, processing them into formats that are needed. Since all the required files don't come at a single time, it is scheduled to RUN every 10 minutes and then it cross-checks for availibility of all the files. Only when all files are present it proccesses them.

In continuation, I have batch files that are scheduled to run one aftaer the other in a particular sequence. The first batch file that is scheduled comes with a PAUSE step, so once I manually confirm that the processed files are in place where the base folder is, I click on RUN in the batch.

I wanted to know whether I can use a python script that opens Amibroker, opens the batch file and then proceeds without the PAUSE, so no manual intervention is needed.

I have researched around a few threads like
http://www.amibroker.com/guide/afl/shellexecute.html
https://forum.amibroker.com/search?q=shell%20execute%20batch

but not very clear how the automation would work. I am able to open broker.exe etc, but still a bit away from being able to open the .abb (Idea would be log each step, as it happens in Amibroker)

I tried running the batch from afl and it worked alright

// === AUTO-GENERATED ===
Title = "Python Trigger AFL";

printf("Running batch from AFL: C:\\Users\\pushkaraj\\Downloads\\EOD Files\\Morning\\00 A Apps & Tools.abb\n");

// Run the Morning batch
ShellExecute("runbatch", "C:\\Users\\pushkaraj\\Downloads\\EOD Files\\Morning\\00 A Apps & Tools.abb", "");


Manually it runs fine. Is there a method to call afl in python code once Amibroker is OPENED.

Method to OPEN Amibroker through COM

Dont mix two different ways.

Either you process everything and then use AB Batch or use the OLE function to open db, import, save db etc.

Usually, on one machine, I always leave AB instance open and just import from whichever relevant script is calling it.
If you try to open AB, then don't close or dispose the handle invoking OLE, AB will not exit but become a background process.
Then you will break your head forever as the subsequent instances you open will be 2nd or more and OLE works only on the first one.

method 1: Run Batch

<path_to_AB\>broker.exe /runbatch <path_to_abb_file>

method 2: OLE method
Python code to import ASCII data - not working - Plug-ins - AmiBroker Community Forum
read this thread till the end