how to run a cmd.exe batch file in a sub shell

前端 未结 2 896
栀梦
栀梦 2021-02-14 21:40

I have a batch file that I usually invoke like this:

 longjob.cmd >result.txt 2>&1

This works fine, but the script changes directory

2条回答
  •  情歌与酒
    2021-02-14 21:50

    Try

    CMD /C longjob.cmd >result.txt 2>&1
    

    Not sure how it'll deal with the redirection, but CMD /C lets you tell CMD what to run and that it should exit when done. (CMD /K lets you tell it to run something but stick around when done.) It will re-use the existing console window if run within one.

提交回复
热议问题