3

all! I'm trying to compile a program using PowerShell, but the command is being parsed strangely. This command executes correctly in cmd.exe:

dmd -od"bin" -of"bin\convHull.exe" -I"src" "src\concSort.d" "src\fileParser.d" "src\main.d" "src\pointLogic.d" "src\quickHull.d" "src\stupidHull.d" -D -O -release

But PowerShell executes it as: (blue, navy, purple texts as they appear in PowerShell ISE)

dmd -od"bin" -of"bin\convHull.exe" -I"src" "src\concSort.d" "src\fileParser.d" "src\main.d" "src\pointLogic.d" "src\quickHull.d" "src\stupidHull.d" -D -O -release

This spits the following error:

The string starting:
At line:1 char:147
+ dmd -od"bin" -of"bin\convHull.exe" -I"src" "src\concSort.d" "src\fileParser.d" "src\main.d"     
"src\pointLogic.d" "src\quickHull.d" "src\stupidHull.d <<<< " -D -O -release
is missing the terminator: ".
At line:1 char:163

So it seems to be interpreting a period as a quote. This is peculiar. Has anyone else had this problem with PowerShell?

Things I've tried:

  1. escaping quotes
  2. making sure all quotes are "straight quotes" and not angled
  3. putting a space before quotes (parses correctly, but the program doesn't understand the arguments.)

Thanks, Charles.

Charles McAnany
  • 195
  • 1
  • 2
  • 7

2 Answers2

2

I believe this should do the trick (newlines added for clarity only, and removal of extra quotes):

dmd '-od"bin"' '-of"bin\convHull.exe"' '-I"src"'
    src\concSort.d src\fileParser.d src\main.d src\pointLogic.d src\quickHull.d src\stupidHull.d
    -D -O -release

Note that in the case where a quote (") is to be passed as part of the argument itself, I surrounded the entire argument with single quotes ('). From the experimentation below it can be seen that only -of"..." needs the quotes about it.

Happy coding.


I can't find a good reference on this exact production, however note the following parsings:

-x"w."   ->  error: " expected (last " is special)
-x"w.""  ->  -x"w and ."" (the . starts a new token and the " in that starts
                           a quote; however, the quotes are not removed)
'-x"w."' ->  -x"w." (extra quote fine, neither special)
-x"w"    ->  -x"w"  (no . and " not special)
-x"w""   ->  -x"w"" (no . and " not special)
a".b"    ->  a.b    (didn't start with `-`, quotes removed)
a".b     ->  error: " expected (" is special)

So it does indeed appear to have something to do with the . and - combination (and it might not be exclusive). From the above I believe that a token starting with - does not include the . character as a valid character in the token so the lexer terminates said token and starts a new token -- easily provable with a good EBNF reference, which I don't have.


The best I can find is Appendix C: The PowerShell Grammar:

The ParameterToken rule is used to match cmdlet parameters such as -foo or - boolProp: . Note that this rule will also match --foobar, so this rule has to be checked before the --token rule.

<ParameterToken> = -[:letter:]+[:]{0 |1}

However, this is incomplete at best and does not even include a definition of "letter".

  • Excellent answer. I am somewhat surprised by the 4th and 5th examples. I'll have to study the parser some more. Maybe it is the lack of punctuation? – JasonMArcher Aug 01 '11 at 15:55
  • @JasonMArcher The " in the 4th and 5th examples *isn't* special because it is part of the token that begins with `-`. It appears, however, that the `.` character will terminate a token starting with `-`. I was taken back by the 6th example (after sorting out the `.` business) because I didn't realize the quotes would be just *removed* (as the quotes do not begin the token and the result is still a single token). It really would be if Microsoft published the official (and complete) grammar/tokenizing rules. –  Aug 01 '11 at 18:31
0

I don't have the executable, but this seems to want to work.

 $cmd = @'
 dmd -od"bin" -of"bin\convHull.exe" -I"src" "src\concSort.d" "src\fileParser.d" "src\main.d" "src\pointLogic.d" "src\quickHull.d" "src\stupidHull.d" -D -O -release
 '@

 &$cmd
mjolinor
  • 66,130
  • 7
  • 114
  • 135