Execute a command asynchronously while redirecting the output to a file in a batch file?

前端 未结 2 674
予麋鹿
予麋鹿 2021-01-15 15:00

Let\'s say in a batch file, I want to execute myCommand asynchronously (without waiting for it to finish). And I don\'t want to execute myCommand in a new

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-15 15:18

    I haven't tested it fully, but I think this may work:

    start /b "" myCommand >output.txt
    

    I believe both forms work fine - the only difference is if standard error is redirected as well and START fails to launch myCommand.

    Redirecting START: both myCommand and START output are redirected to the file.

    start /b "" myCommand >output.txt >2&1
    

    Redirecting myCommand only: Only myCommand output is redirected. Any START error message will appear on the screen. Note, I opted to escape the redirection instead of using quotes like jeb.

    start /b "" myCommand ^>output.txt ^>2^&1
    

提交回复
热议问题