0

Quoting the whole argument with an extra quotes, does not work.

    char command[256] = R"(""D:\src has space" "E:\dest has space" /I /Y /E")";

    auto process = CreateProcessA(
    //"Project1.exe", //my test program below
    R"(C:\Windows\system32\xcopy.exe)",
    command,
    nullptr,
    nullptr,
    true,
    CREATE_NO_WINDOW,
        nullptr,
    ".",
    &si, &pi
    );

I got Invalid number of parameters.

I wrote a little program to print out the arguments, one by one and then showing in a messagebox.

#include <windows.h>
#include <string>

int main(int argc, char** argv)
{
    std::string s = std::string{"argc = "} + std::to_string(argc);
    s += '\n';
    for (int i = 0; i<argc; ++i)
    {
        (s += argv[i]) += '\n';
    }
    MessageBoxA(NULL, s.data(), "Caption", 0);
}

This is obviously not correct.enter image description here

Removing the extra quotes does not work either

char command[256] = R"("D:\src has space" "E:\dest has space" /I /Y /E)";

I got 0 File(s) copied enter image description here

sz ppeter
  • 1,698
  • 1
  • 9
  • 21
  • 1
    Documentation [says](https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessa): `Console processes written in C can use the argc and argv arguments to parse the command line. Because argv[0] is the module name, C programmers generally repeat the module name as the first token in the command line... If lpApplicationName is NULL, the first white space–delimited token of the command line specifies the module name.` – dewaffled Nov 19 '22 at 09:53

0 Answers0