2

I use system to call an external excutable file with argument list.

string all = (excuteablePath + " " + inputDir + " " + outputDir + " " + spacing);
system(all.c_str());

The value of string all shown in IDE or with cout is

.\sample.exe .\孙夏^4735\UR7\ .\孙夏^4735\UR7.stl 0.3 0.3 0.3

but the output from the executable is

.\sample.exe .\孙夏4735\UR7\ .\孙夏4735\UR7.stl 0.3 0.3 0.3

The character ^ disappered.

Why is this happened and how may I solve this?

François Andrieux
  • 28,148
  • 6
  • 56
  • 87
Summer Sun
  • 947
  • 13
  • 33
  • 3
    This may be related to the fact that `^` is a special escape character for the Windows console. See https://stackoverflow.com/questions/20342828/what-does-symbol-means-in-batch-script – François Andrieux Mar 29 '18 at 14:50

1 Answers1

1

Ideally you should use wide string characters and CreateProcess

std::wstring wstr =
    L".\\sample.exe .\\孙夏^4735\\UR7\\ .\\孙夏^4735\\UR7.stl 0.3 0.3 0.3";
STARTUPINFOW si = { sizeof(si) };
PROCESS_INFORMATION pi;
CreateProcessW(0, &wstr[0], NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi);

Note the W after STARTUPINFO and CreateProcess

If you are forced to use ANSI code page then use the ANSI version of CreateProcess

std::string str =
    ".\\sample.exe .\\孙夏^4735\\UR7\\ .\\孙夏^4735\\UR7.stl 0.3 0.3 0.3";
STARTUPINFOA si = { sizeof(si) };
PROCESS_INFORMATION pi;
CreateProcessA(0, &str[0], NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi);
Barmak Shemirani
  • 30,904
  • 6
  • 40
  • 77