"Don't quote me on this", I said (03 Apr 2007)

A good while ago, I discussed how the idiosyncratic command-line parsing rules in cmd.exe can hurt code which uses C runtime APIs such as system, and how to soothe the pain using mildly counterintuitive, yet simple quoting rules:

  • Quote the command
  • Quote all arguments
  • If both the command and at least one of the arguments contain blank characters, quote the whole command line as well.

This works for almost all situations except if you use start:

  C:\>start /b "c:\Program Files\Microsoft Visual Studio 8\Common7\Tools\Bin\uuidgen" 
            -ofoobar.txt

Try the above in a command prompt (everything in one line!): "The system cannot find the file -ofoobar.txt".

When asking for syntax help (start /?), we get:

I:\>start /?
Starts a separate window to run a specified program or command.

START ["title"] [/D path] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
      [/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
      [/AFFINITY <hex affinity>] [/WAIT] [/B] [command/program]
      [parameters]

    "title"     Title to display in  window title bar.
    ...

Note the optional title argument and how it can create a syntactical ambiguity. In "start some command", which part of the command line is the title and which is the command? This may or may not be the reason why start trips over command names which contain blank characters - but the optional title argument also provides the workaround for the problem:

  C:\>start "eureka" /b "c:\Program Files\Microsoft Visual Studio 8\Common7\Tools\Bin\uuidgen"
          -ofoobar.txt

In fact, an empty title string will do just as well:

  C:\>start "" /b "c:\Program Files\Microsoft Visual Studio 8\Common7\Tools\Bin\uuidgen"
          -ofoobar.txt

The above example is a little contrived - but the problem is real; recently, it affected some customers when we changed installation paths for our products at CoCreate.



When asked for a TWiki account, use your own or the default TWikiGuest account.



to top

You are here: Blog > BlogEntry20070403

r1.3 - 03 Apr 2007 - 19:25 - ClausBrod to top

Blog
This site
RSS

  2017: 12 - 11 - 10
  2016: 10 - 7 - 3
  2015: 11 - 10 - 9 - 4 - 1
  2014: 5
  2013: 9 - 8 - 7 - 6 - 5
  2012: 2 - 10
  2011: 1 - 8 - 9 - 10 - 12
  2010: 11 - 10 - 9 - 4
  2009: 11 - 9 - 8 - 7 -
     6 - 5 - 4 - 3
  2008: 5 - 4 - 3 - 1
  2007: 12 - 8 - 7 - 6 -
     5 - 4 - 3 - 1
  2006: 4 - 3 - 2 - 1
  2005: 12 - 6 - 5 - 4
  2004: 12 - 11 - 10
  C++
  CoCreate Modeling
  COM & .NET
  Java
  Mac
  Lisp
  OpenSource
  Scripting
  Windows
  Stuff
Changes
Index
Search
Maintenance
Impressum
Datenschutzerklärung
Home



Jump:

Copyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback