In my batch file I've got the following code
SETLOCAL enabledelayedexpansion
7Z a -r ..\%ZIPNAME%.zip * >> uniqueid8.log
IF !ERRORLEVEL! GEQ 1 (
CALL :getLineNumber errLine uniqueID8 -2
PHP ..\..\shell_mailupdate.php ERROR !errLine! "7Z a -r ..\%ZIPNAME%.zip * >> ..\uniqueid8.log"
ENDLOCAL & EXIT /B
)
ENDLOCAL
:getLineNumber
is a function to get the line number:
:::::::::::::::::::::::::::::::::::::::::::::
:GetLineNumber <resultVar> <uniqueID> [LineOffset]
:: Detects the line number of the caller, the uniqueID have to be unique in the batch file
:: The lineno is return in the variable <resultVar> add with the [LineOffset]
SETLOCAL
for /F " usebackq tokens=1 delims=:" %%L IN (`findstr /N "%~2" "%~f0"`) DO set /a lineNr=%~3 + %%L
(
ENDLOCAL
set "%~1=%LineNr%"
goto :eof
)
Shell_mailupdate.php is php script which send me error information.
The batch file is called asynchronously from my web application using this function found on the exec page of php:
<?php
function execInBackground($path, $exe, $args = "") {
global $conf;
if (file_exists($path . $exe)) {
chdir($path);
if (substr(php_uname(), 0, 7) == "Windows"){
pclose(popen("start \"bla\" \"" . $exe . "\" " . escapeshellarg($args), "r"));
} else {
exec("./" . $exe . " " . escapeshellarg($args) . " > /dev/null &");
}
}
}
?>
When the batch file is called (my server OS is Windows), I receive a mail telling me that the command didn't work and my batch is interrupted. And when I go to see the unique8.log, it is empty. But when I try this command directly (by replacing %ZIPNAME% by the name I want) on the server it works and create my zip file. There are also other call of the 7-zip command to extract data earlier on the script, but I suspect they didn't work too, as the data didn't get extracted. But I know the batch file runs smoothly when started manually.
It can't come from the variable, as I know from my mail that it was correctly intialized. I also have the last version of 7-zip installed.
EDIT: For those wondering why I do have such a configuration, I need to create big bundle out of many little bundle. This involved unpacking the little bundle and rearranging their content. As the operation is time consuming, I simply call this operation in the background and let my php script finish without waiting for the operation to finish, and it tells the end-user that a mail will be sent as soon as the operation is through.
EDIT2: After following Wimmel advice to write stderr in the log file, I got the following exception:
Der Befehl "7Z" ist entweder falsch geschrieben oder konnte nicht gefunden werden.
Which roughtly translate into
The command "7Z" is either written uncorrectly or couldn't be found
This is weird because, as I mentioned earlier, calling the batch script manually goes smoothly without such an exception.