Batch string replace

淺唱寂寞╮ 提交于 2019-12-29 09:19:05

问题


I have a variable like this

"Folder With Spaces/filename.ext"

When I pass it to my program via PHP's system command, arguments are separated by spaces

system("batch.bat Folder With Spaces/filename.ext");

So I have it like this

system("batch.bat Folder_With_Spaces/filename.ext");

Is there a way now that it is back in the batch program to replace the _'s with 's


回答1:


try this in your batch file:

set str=hello_world_try_this
set str=%str:_= %
echo.%str%



回答2:


Just enclose the parameter that has spaces with quotes.

system("batch.bat \"Folder With Spaces/filename.ext\"");



回答3:


You may want to try escapeshellcmd(), like this:

$path = escapeshellcmd("Folder With Spaces/filename.ext");  
system("batch.bat \"$path\"");


来源:https://stackoverflow.com/questions/3646016/batch-string-replace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!