Using the DOS launch command when the arguments passed have quotes

I have a question about the DOS launch command. I already read this topic: Using the DOS "Start" command with parameters passed to the running program Using the "start" command with parameters passed to the running program

but my question is a little different.

I have this problem: I need to pass the paths that need to be pointed.

For example, if the path does not have quotes, this works fine:

start "" app.exe -option c: \ myapp \ myfile.txt

but if the path has double quotes, it does not work.

I have this line in my BATCH file:

start "" myapp.exe -option% mypath%

and when% mypath% contains double quotes (paths that have spaces or other characters in the names), the start command returns very strange results.

Thanks Sandro

+4
source share
2 answers

Usually it is not a problem to use parameters there with quotes, but you get problems if your path to the application is also quoted.

Then you need to add an additional CALL statement.

 start "" app.exe -option c:\myapp\myfile.txt - Works start "" app.exe -option "c:\myapp\myfile.txt" - Works start "" "app.exe" -option c:\myapp\myfile.txt - Works start "" "app.exe" -option "c:\myapp\myfile.txt" - Don't works start "" CALL "app.exe" -option "c:\myapp\myfile.txt" - Works 
+3
source

This may help, but it is a bit around method, and small changes may be required to suit your needs.

The idea is as follows:

  • Dump an environment variable that has quotation marks into a text file with a predefined name. For example: "set mypath2> withQt.bat"
  • Use the windows shell or some third-party tool to find and replace quotes in this file.
  • Create another text file (only once) containing the "Install" line
  • Use the copy command to add the file mentioned in step 2 with the file created in step 3 and create a batch file with a predefined name. For example: copy base.bat + withQt.bat withtqt.bat
  • Run a batch file that creates another / replaces the environment variable with the value without quotes.

Sorry, I could not get something more elegant at this time.

+1
source

Source: https://habr.com/ru/post/1396274/


All Articles