dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: system() fails to parse argument

  1. #1
    Join Date
    Nov 2012
    Location
    Edinburgh
    Posts
    20

    system() fails to parse argument

    I have a very strange problem with the system() function (on XP).

    I have the following code:
    Code:
    char *text1 = "\"A Space\\Action.bat\" fred";
    char *text2 = "\"A Space\\Action.bat\" \"fred\"";
    
    int main(int argc, char *argv[]) {
       printf("%s\n", text1);
       system(text1);
       printf("%s\n", text2);
       system(text2);
       return 0;
    }
    When I run it where "A Space" is a directory with a space in the name, this is the result:

    Code:
    "A Space\Action.bat" fred
    
    F:\Test>echo Testing
    Testing
    "A Space\Action.bat" "fred"
    'A' is not recognized as an internal or external command,
    operable program or batch file.
    It seems that the double quotes round an argument make the parsing of the command fail.
    Can anyone suggest a solution?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,456

    Re: system() fails to parse argument

    What happened if you'd execute the following command in the command
    Code:
    F:\Test>"A Space\Action.bat" fred
    prompt directly?
    Victor Nijegorodov

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)