Batch string replace
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.ex开发者_JAVA百科t");
Is there a way now that it is back in the batch program to replace the _
's with 's
try this in your batch file:
set str=hello_world_try_this
set str=%str:_= %
echo.%str%
Just enclose the parameter that has spaces with quotes.
system("batch.bat \"Folder With Spaces/filename.ext\"");
You may want to try escapeshellcmd(), like this:
$path = escapeshellcmd("Folder With Spaces/filename.ext");
system("batch.bat \"$path\"");
精彩评论