Click to See Complete Forum and Search --> : Post-build event command line is screwy; only one argument passed to the app?


cjard
May 9th, 2008, 10:42 AM
Hi all.. I have the following post build:

rexcopy.exe "$(TargetDir)" "(.*\.dll|.*\.tlb)" "d:\published\$(SolutionName)"



rexcopy is an exe i wrote to copy files regular expression matched on the name. it needs 3 arguments, the source dir, the regex, and the dest dir. It wasnt working with this post-build so i put some console WriteLines in to reveal what arguments it is receiving and it gets only one:


c:\windows\rexcopy.exe "C:\Documents and Settings\MyProj\bin\Release\" "(.*\.dll|.*\.tlb)" "D:\Published\MyProj"

Argument: C:\Documents and Settings\MyProj\bin\Release\" "(.*\.dll|.*\.tlb)" "D:\Published\MyProj
1 arguments specified

RexCopy

rexcopy.exe <sourceDir> <filenameRegex> <destDir> [/c] [/o]

<sourceDir> = a full path of the dir to hunt for files
<filenameRegex> = a regular expression to match filenames with
<destDir> = a full path of the dir where to put files
/c = clear dest dir first
/o = overwrite existing files


expected:

c:\windows\rexcopy.exe "C:\Documents and Settings\MyProj\bin\Release\" "(.*\.dll|.*\.tlb)" "D:\Published\MyProj"

Argument: C:\Documents and Settings\MyProj\bin\Release\
Argument: (.*\.dll|.*\.tlb)
Argument: D:\Published\MyProj
3 arguments specified

RexCopy

rexcopy.exe <sourceDir> <filenameRegex> <destDir> [/c] [/o]

<sourceDir> = a full path of the dir to hunt for files
<filenameRegex> = a regular expression to match filenames with
<destDir> = a full path of the dir where to put files
/c = clear dest dir first
/o = overwrite existing files

any idea what gives?

cjard
May 9th, 2008, 11:03 AM
it's something screwed up with "$(TargetDir)"

If I hard code the path to be "c:\temp" or soemthing, then it works fine..
If I put "$(TargetDir)" as the last argument on the line then look:

Argument: C:\Documents and Settings\MyProj\bin\Release\"

What's the quote doing there?



Can someone else check this for me? Make a new console app called ListArgs, here is the code:

using System;
using System.Collections.Generic;
using System.Text;

namespace ListArgs
{
class Program
{
static void Main(string[] args)
{
foreach (String s in args)
Console.Out.WriteLine(s);
}
}
}

simple.. :)

Now go into that project properties, BUILD tab and put it to OUTPUT TO c:\windows (its on the path)

Now go into BUILD EVENTS and paste thisi n the Post build:

ListArgs.exe "something first" "$(TargetDir)" "$(TargetDir)" "$(TargetDir)" "something else"


heres what mine prints:


------ Rebuild All started: Project: ListArgs, Configuration: Debug Any CPU ------

Compile complete -- 0 errors, 0 warnings
ListArgs -> C:\windows\ListArgs.exe
ListArgs.exe "something first" "C:\windows\" "C:\windows\" "C:\windows\" "something else"
something first
C:\windows" C:\windows"
C:\windows" something
else
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========


What the heck are those arguments supposed to be?

dglienna
May 9th, 2008, 11:12 AM
there's a space in the path. Use a , as separator, or just about any disallowed path variable.

cjard
May 9th, 2008, 11:35 AM
I think i just worked it out...

$(TargetDir) ends with a trailing slash for ?convenience?

But this trailing slash seems to be escaping the next quote, meaning that ?DOS? is thinking the call to:

ListArgs.exe "C:\windows\"

is one argument of: c:\windows"


This is nearly the stupidest thing i've ever seen.. how to work around that?

cjard
May 9th, 2008, 11:42 AM
there's a space in the path. Use a , as separator, or just about any disallowed path variable.

What does that mean?



I dont suppose anyone else noticed that the macro that gives us the path of where an MSI file (Setup project) was built is called $BuiltOuputPath - i missed the two typos (Built vs Build, Ouput vs OuTput) up til now..
..doesnt fill me with confidence



ANyways, my workaround was:

rexcopy.exe "$(TargetDir)."

Notice the period at the end of the macro? It expands now to:


DOS EXECUTE: rexcopy.exe "C:\whatever\."

the trailing period prevents \ making the quote literal

TheCPUWizard
May 10th, 2008, 12:21 PM
I think i just worked it out...

$(TargetDir) ends with a trailing slash for ?convenience?

But this trailing slash seems to be escaping the next quote, meaning that ?DOS? is thinking the call to:

ListArgs.exe "C:\windows\"

is one argument of: c:\windows"


This is nearly the stupidest thing i've ever seen.. how to work around that?

That is correct, it is one of the most "unusual" situations, and causes lots of people to get confused. Howere it is much more common to use the path in conjunction with a file name. If the "\" was not there, then everyone else would have to add it.

The best solution, if you really want to pass the path (and are not using it to build a FILE specification, it to simply append a ".".

This is fairly self documenting as "I want the current directory pointed to by the Target Directory".

So

$(TargetDir).
$(TargetDir)..
$(TargetDir)NewFileName
$(TargetDir)($OtherParam)
....