Direkt zum Inhalt

ATI is not detecting failure from Pre-command batch file

Thread needs solution

As I mentioned here a few weeks ago, I created a batch file to run as a pre-command to determine whether or not to run a backup based on the day. I worked OK on my Windows 10 machine but when I put it on the Windows 7 Pro machine yesterday, the command never failed. I created this test batch file...

@echo off
set errorlevel=1
exit /b 1

Very simple... it should return 1 and the pre-command should consider that a failure. (Yes, I realize I'm being redundant there.) But it does not. Running the batch file from a command prompt and then testing errorlevel shows the batch file doing what it is supposed to do. I tried everything I could think of to get the batch file to return an error condition to Acronis, but no luck.

Can someone test this on a Windows 7 Pro machine and see if their Acronis catches the error.

 

0 Users found this helpful

Bruno, tested your simple batch commands on both Windows 10 and Windows 7 systems running ATIH 2017 and got the same result on both, that the "Execution of the user command has failed." as expected for setting a failure errorlevel return code.

Steve, I've been doing some more testing and here's what I am experiencing.

If I simply add a pause statement to the script above, then the test will hang. But then, if I remove the .bat extension in the pre-command, it will run but it will always return successful.

Apparently there is something in my original desired script which is doing the same thing the pause statement is doing.

Any ideas?

Bruno, if you use pause then it requires user interaction to move on, so is there something in your full script that may be needing the same?

Steve, in adding the pause statement, the command window opens up but never executes anything in the batch file as the command box is empty. Normally, the pause will display a message to press any key to continue.

I made a copy of the file and changed the extension from .bat to .cmd. Then, it executed and the pause caused the appropriate message. When I pressed the key to continue, the result was successful even though it should not be.

So why was the file not being executed as a .bat file with the pause statement. My other script has the same reaction but there is no pause there. Apparently something else is amiss.

Further test...

The batch file contains three line...
  @echo off
   pause
   exit /b 2

There are two versions, one with .bat file type and one with .cmd file type.

I opened a command prompt outside of Acronis and tested them by executing the file and then testing errorlevel...

C:\>ErrorTest.bat
Press any key to continue . . .
C:\>echo %errorlevel%
2
C:\>>ErrorTest.cmd
Press any key to continue . . .
C:\>echo %errorlevel%
2

This looks good. But within Acronis I am not getting the same result. The .bat file will not execute; the .cmd file will execute but with a successful return.

 

 

Bruno, to be honest I believe that there are some issues with running .bat or .cmd files from within ATIH that have been reported and discussed in these forums many times without a satisfactory solution being found.

There are two ways forward that I can think of:  

  1. Raise this as a Support Case directly with Acronis and see if they can fix this in this or a future build.
  2. Approach the problem you are trying to solve with the Pre/Post Commands in a different way, i.e. if I remember the original topic you raised, it was to run the backups on certain days and not on others, so perhaps a different approach might be to create a BackupToday.txt file on those days when the backup should be run, and remove/delete the file on the days it should not run, then do a simple test for the file every time the backup runs - if found run it, if not don't.

In reply to by truwrikodrorow…

"... then do a simple test for the file every time the backup runs..."

What method of test do you suggest, Steve?

If exist filename then ...

FYI, here is my final working method:

On Windows 7, the only way I could get it right is to rewrite the batch file as a .vbs file. In the pre-command, I run a small batch file which calls the VB script and then passes back the errorlevel.

After some small tweaks, I got this method to now work on both systems.

Well done for persevering with this Bruno, glad to hear you have a working solution.