Winnt Cmd.exe/c Issue: Bad Parsing Of Filename W/ Quoted Batch File String

Discussion in 'Software' started by HarryPotter, Oct 27, 2018.

  1. HarryPotter

    HarryPotter MajorGeek

    Hi! I am working on a program written in C for Windows that calls an external console program and am having an issue: when I call the external program with the path quoted through the cmd.exe utility, cmd.exe says that the whole string is not a valid command or file. Without quotes, the program works properly. I'm using the CreateProcess() function to run the external program, using the /c switch before the filename, passing the utility a file and postfixing "& pause" to the command line to pause the execution upon exit. What could be causing the problem?
     
  2. _nullptr

    _nullptr Major Geeky Geek Geek

    Most likely you're not escaping the quoted path correctly. It would help if you posted the relevant code.
    An example of a properly escaped path is:
    Code:
    LPWSTR ws = L"\"quoted\\file\\path\"";
    
     
  3. HarryPotter

    HarryPotter MajorGeek

    The following is the command line:
    Code:
    /c "C:\Emulators\C64\exomizer-2.0.10\win32\exomizer.exe" sfx basic -t64 -x1 -o "compress64.prg" "compress64.prg"&pause 
    The following is the code to execute the program:
    Code:
    static void writecmd (void) 
    { 
            strcpy (cmd, "/c  \""); 
            strcat (cmd, exomdir); 
            strcat (cmd, "\\exomizer.exe\" sfx basic -t"); 
            //itoa (systxt, flags.sys, 10); strcat (cmd, systxt); 
            sprintf (systxt, "%d", flags.sys); strcat (cmd, systxt); 
            strcat (cmd, " -x1 -o "); 
            strcat (cmd, file); 
            strcat (cmd, " "); 
            strcat (cmd, file); 
            strcat (cmd, "&pause"); 
    } 
    
            CreateProcess ( 
                    comspec, 
                    cmd, 
                    0, 
                    0, 
                    0, 
                    CREATE_NEW_CONSOLE, 
                    0, 
                    lpath, 
                    &start, 
                    &inf); 
            WaitForSingleObject (inf.hProcess, INFINITE); 
            CloseHandle (inf.hProcess); 
            CloseHandle (inf.hThread);
    Does this help?
     
  4. _nullptr

    _nullptr Major Geeky Geek Geek

    The answers here should help you.
     
    HarryPotter likes this.
  5. HarryPotter

    HarryPotter MajorGeek

    I didn't know that. Thanks! :)
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds