简体   繁体   中英

Want to execute two commands in windows batch file one by one

I want to send the spool files to printer from spool folder one by one and after processing each file it will be moved to another folder or delete it. But When I'm trying to run below batch file it directly moves spool files without sending to printer which is due to batch processing.

 for %%f in (C:\WINDOWS\system32\spool\PRINTERS\*.SPL) do (
            echo %%~nf
            start "" E:\spool\xyz\tp.exe "C:\WINDOWS\system32\spool\PRINTERS\%%~nf.SPL" "HP Printer"
            move "C:\WINDOWS\system32\spool\PRINTERS\%%~nf.SPL" d:\%%~nf.txt
        )

SO need any alternative option without using windows PowerShell.

Thanks in advance.

It is not because of the batch processing. By default batch waits on the termination of a command before moving on. So leaving out the start should do.
The problem is actually the start command. By default start will execute the program as a new process and won't wait for it to finish. Use start /WAIT instead, the /WAIT option will ask it to wait. But as I said earlier, you don't even need start . Supposing your program exits when it has completed its task, you should do:

for %%f in ("C:\WINDOWS\system32\spool\PRINTERS\*.SPL") do ( 
    echo %%~nf
    E:\spool\xyz\tp.exe "%%~ff" "HP Printer"
    move "%%~ff" d:\%%~nf.txt 
)

In general that should do. But if the program E:\\spool\\xyz\\tp.exe itself starts some kind of background process and exits without waiting for it to terminate, even start /WAIT won't help. As I don't know the program you're using ( E:\\spool\\xyz\\tp.exe ) I won't be able to help you in that case.

EDIT : Just a little improvement I made in the code: you don't need to specify the whole path to get the file corresponding to the loop variable, %%~ff will do it for you (see this link for others).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM