Batch command line thread, was: Inserting time lag in command

Tags: #<Tag:0x00007fb3df5996c0>


Dear Forum,

I am trying to automate the batch process wherein once I export results of explorations to csv files (multiple files), I open these files which in turn are linked to an EXCEL file. The process is quiet fast as for the command line but the drawback is since multiple OPEN commands are passed it sometimes over-runs wherein a few of the csv files get OPEN in READ only. A way out in my opinion is to introduce a lag either through "SLEEP & ECHO" , but am still not clear how the syntax would work. Can anybody guide a bit. The base "execute & wait" command would look something like below:

cmd.exe /c start excel "D:\Daily Datapoints\07 - OPT Val Macro-Micro-MWPL\07 Raw\MAC.csv"
cmd.exe /c start excel "D:\Daily Datapoints\07 - OPT Val Macro-Micro-MWPL\07 Raw\MACB.csv"
cmd.exe /c start excel "D:\Daily Datapoints\07 - OPT Val Macro-Micro-MWPL\07 Raw\MWPL.csv"
cmd.exe /c start excel "D:\Daily Datapoints\07 - OPT Val Macro-Micro-MWPL\07 FO Val Macro-Micro.xlsx"

The "Pause" here stops till manual intervention in not done, I just want to put in SLEEP &/or ECHO inside the surface flow


There is a DOS/Windows command called TIMEOUT.

You can probably use that to pause multiple seconds as needed or until a key press (using -1 as a parameter).
Use it in a execute and wait line.

I did not test it but I think it will work.

At the command prompt type: timeout /? to get the command syntax.

P.S. Searching for it on StackOverflow I see this note: “Timeout is poorly implemented. If you do a “timeout 1”, it will wait until the “next second,” which could occur in .1 seconds. Try doing “timeout 1” a few times and observe the difference in delay. For 5 seconds or more, it may not be a big deal, but for a 1 second delay it works poorly. (Dan)”


There is Pause command in the Batch processor already. You can use JScript to sleep for specified number of seconds, you can put all your command line calls into single BAT file. There are literally dozens of possibilities.


Yes the timeout just worked out well. Now to the next level, where the files that export csv files are lnked. Am attaching the screenshot
Select Y
Now how do we use auto YES for “Update”, “Save”


@pushkan, I’m not sure to understand the issue (the confirmation dialog screenshot you posted does not show “Update” or “Save” buttons) but I suggest you do to some Google searching!
(This seems to be out of the realm of AB):

For instance typing “Excel how to automatically update external links without a confirmation dialog” I found:

How to disable update links message when open a workbook?

and more specifically:

Disable update links message with Excel Options


So far so good. The system works well on a local machine, however when run from a network drive, it holds back as the file opens as “Read Only” thereby not updating my final excel sheet.

While on the matter, is there any way to save changes and then close (taskkill) the said file after saving?


@pushkan what “file”?
Are you referring to the (multiple) .cvs files written by the exploration? Are these the files that are in “read-only mode” when you attempt to open them from a network machine?
In such a case, are you able to copy these file (test this both locally and/or to a remote/network destination) using a standard DOS command line copy command and then open the copied file in the required application (Excel)?


@beppe, Yes the files are multiple csv files created through exploration which in turn feed to an excel (xls) file/ sheet


Just for reference, am adding a few screenshots:


The work around is sharing tha macros run-up. That went off succesful.


Initiating an alternate reply as only 1 image is allowed per post

However in the next step stuck that with file being locked for editing by “another user”. Actually there is no such user, as I tried by disabling the “Sharing”


The bottomline still stuck up !!!


A byproduct, is there a way to SAVE an xls file through the command line?


The message that Excel displays is misleading. Excel always locks files exclusively it is not “another user”, but “Excel” who locked the file and Excel is the culprit. Google has TONS of posts about that.


Yes indeed it's a BUG on earlier versions of Office &/or Windows. Upgrading to Office 2010 helped.
Thanks Tomasz,
The issue is way beyond the purview of Amibroker, but the forum helps get through the roadblocks.


Though not directly related to topic would like to know how to run an exe file in a specified folder, through the batch file process. The default path is set to "C:\Program Files\Amibroker", hence If I run in the command as cmd.exe /c start ITMCDRun.exe
it will run succesfully. But I wish to run it through a specified folder like
cmd.exe /c start "E:\Converters & Downloaders\ITM CD JAN 2018\ITMCDRun.exe"

Please advise


@pushkan for executable you can invoke them using this syntax:

ShellExecute(executableFilename, executableParameters, executablePath, 0);

I tested it, as follows, on a machine of mine with an old executable that accepts parameters, and that was not included in the Windows Path.

ShellExecute("lazarus.exe", "C:\\Dev\\lazarus\\examples\\barchart\\chartdemo.lpr", "C:\\dev\\Lazarus", 0);

Review the Amibroker documentation and check the corresponding Windows Shell function for error codes.

As always be sure to include the passed values using the " " quotes (as in your example) if they contain any spaces.


Dear Beppe,

What happens if there are no executable parameters ?

ShellExecute("lazarus.exe", "C:\Dev\lazarus\examples\barchart\chartdemo.lpr", "C:\dev\Lazarus", 0);

ShellExecute("ITMCDRun.exe", 0, "E:\Converters & Downloaders\ITM CD JAN 2018", 0);

I am including in the GUI



@pushkan use an empty string:

ShellExecute("lazarus.exe", "", "C:\\dev\\Lazarus", 0);

NOTE The Above syntax is for the ShellExecute function when called from AFL formulas not for the "Batch" Execute & Wait operation (as per your screenshot). I missed that point from you previous message, sorry!


The easiest way to use it from an AmiBroker batch is to launch a DOS/Windows batch file in which you do all the necessary steps (including changing the working folder). This was already suggested above by @Tomasz.

For example to launch it from the "Batch" Execute & Wait I entered:


and create a "laz.bat" in the the above folder (C:\dev\lazarus) as follow:

CD \dev\lazarus
timeout 5


Thanks @beppe - the batch file concept did it.


An add-on, would it be possible to trigger an exe on different machine. Idea is not to open the instance of exe in current machine, but it should open in the other machine itself.