CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Post-build event command line is screwy; only one argument passed to the app?

    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:

    Code:
    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:
    Code:
    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?
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

  2. #2
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: Post-build event command line is screwy; only one argument passed to the app?

    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:
    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:
    Code:
    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?
    Last edited by cjard; May 9th, 2008 at 11:11 AM.
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Post-build event command line is screwy; only one argument passed to the app?

    there's a space in the path. Use a , as separator, or just about any disallowed path variable.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #4
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: Post-build event command line is screwy; only one argument passed to the app?

    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?
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

  5. #5
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: Post-build event command line is screwy; only one argument passed to the app?

    Quote Originally Posted by dglienna
    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
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

  6. #6
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Post-build event command line is screwy; only one argument passed to the app?

    Quote Originally Posted by cjard
    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
    Code:
    $(TargetDir).
    $(TargetDir)..
    $(TargetDir)NewFileName
    $(TargetDir)($OtherParam)
    ....
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured