4

I have a question about the DOS start command. I have already read this topic: Using the DOS “start” command with parameters passed to the started program Using the "start" command with parameters passed to the started program

but my question is a little different.

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

For example, if path have no quotes this works fine:

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

but if path have double quotes it doesn't works.

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 names) the start command returns very strange results.

Thanks Sandro

Community
  • 1
  • 1
gialloporpora
  • 149
  • 2
  • 11

2 Answers2

3

Normally it's not a problem to use parameters there with quotes, but you get problems if your app-path has also quotes.

Then you need to add an extra 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
jeb
  • 70,992
  • 15
  • 159
  • 202
  • Ahh nice, you're running the "call" command and then passing the program and arguments to that. Note for Googlers: -option is not a part of the generic answer, it's just there because it was in the asker's question. – Andrew Aug 05 '17 at 02:15
  • **Also note that you could just call cd "path" beforehand.** The start command has a /d option to set the working directory for the command it calls/process it starts. – Andrew Aug 05 '17 at 02:16
  • Also add CMD /C to prevent a hang of new opened window, if you invoke a `.bat` file - `START "dummy header" CMD /C CALL "C:\my apps\my.bat" "param - 1" param_2` – it3xl Apr 05 '18 at 15:19
1

This might help, but it is a bit way round about method and slight modification may required to suit your need.

The idea is to:

  1. Dump the environment variable which has quotes to a text file with a predefined name. Like:"set mypath2 > withQt.bat"
  2. Use windows power shell or some third party tool to find and replace quotes in that file.
  3. Create another text file (one time step only) containing string "Set "
  4. Use copy command to append the file mentioned in step2 with the file created in step3 and create a batch file with a predefined name. Like: copy base.bat + withQt.bat withtqt.bat
  5. Run the batch file, which creates another/replaces the environment variable with value without quotes.

Sorry, I couldn't get something more elegant at this time.

Community
  • 1
  • 1
Narayanan
  • 3,156
  • 2
  • 16
  • 24