Removing double quotes from variables in batch file creates problems with CMD environment

前端 未结 11 586
春和景丽
春和景丽 2020-12-04 11:25

Can anybody help with effective and safe way of removing quotes from batch variables?

I have written a batch file which successfully imports a list of parameters %1,

11条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-04 11:51

    Your conclusion (1) sounds wrong. There must be some other factor at play.

    The problem of quotes in batch file parameters is normally solved by removing the quotes with %~ and then putting them back manually where appropriate.

    E.g.:

    set cmd=%~1
    set params=%~2 %~3
    
    "%cmd%" %params%
    

    Note the quotes around %cmd%. Without them, path with spaces won't work.

    If you could post your entire batch code, maybe more specific answer could be made.

提交回复
热议问题