Okay so here’s the lowdown… been working on this solution for the past week or so, thought I had it down but it seems something is amiss… Here’s my code and I’ll give the logic breakdown:
::Programs
SET fox=C:\Program Files\Foxit Software\Foxit Reader\Foxit Reader.exe
SET spool=C:\WINDOWS\system32\PRNJOBS.vbs
::Directories
SET new=C:\PDF\New
SET printing=C:\PDF\Printing
SET finish=C:\PDF\Finish
SET errorfiles=C:\PDF\Error Files
::Important Files
SET syslog=C:\PDF\Script_Messages\PrintLOG.txt
SET emaillog=%tmp%\PrintLOG.txt
SET errlog=C:\PDF\Script_Messages\ErrorLOG.txt
SET emailerr=%tmp%\ErrorLOG.txt
CD "%new%"
MOVE /Y "*.pdf" "%printing%"
CD "%printing%"
FOR %%F IN (*.*) DO (
START "" /B "%fox%" -p "%%~fF"
FOR /F "USEBACKQ tokens=1*" %%A IN (`CSCRIPT "%spool%" -l ^| FIND /I "%%F"`) DO (
MOVE /Y "%%B" "%finish%\%%~nxf"
ECHO %%~nxF>>"%syslog%"
ECHO %%~nxF>>"%emaillog%"
IF EXIST "%%~fF" (
MOVE /Y "%%~fF" "%errorfiles%\%%~nxF"
ECHO *****ERROR PRINTING FILE***** %%~fF>>"%errlog%"
ECHO *****ERROR PRINTING FILE***** %%~fF>>"%emailerr%"
)
)
)
Move files from NEW folder to PRINTING folder. For every file in printing folder, print it using foxit, and for every entry in the PRNJOBS.VBS command in which I find the filename, move the file to finish folder, and echo the log entries for success, then if the file still exists in its old directory, move the file to errorfiles folder and echo the log entires for error in printing.
The script exits without any errors, but it seems like on line 22 is where the script exits. I check the files, and they never get moved to %finish% directory so it has to have been killed on line 22.
If you send a file to your print queue then run
C:\WINDOWS\system32\PRNJOBS.vbs -l
in your CMD you’ll see how that command sends its stdout.
This may be the cause of the problem:
It should be
because loop variable names are case sensitive and your loop variable (other than
%%A) is declared as%%F.