php - Batch string replace

522

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

937

Answer

Solution:

try this in your batch file:

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

Answer

Solution:

Just enclose the parameter that has spaces with quotes.

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

Answer

Solution:

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

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

People are also looking for solutions to the problem: php - pdo mysql select statement working on one table while it is not working on other

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.