Usually one could use ^
to escape a character in the command-line. But I couldn't make it to work.
Here is a test program, CommandArguments.exe, which prints the arguments it got.
int main(int argc, char *argv[])
{
int i, j;
for (i = 0; i < argc; ++i) {
printf("%d: %s\n", i, argv[i]);
for (j = 0; j < strlen(argv[i]); ++j) {
printf(" ");
printf("%d ", argv[i][j]);
}
printf("\n");
}
}
The program in question, LineBreakCommandArguments.exe, is as follow:
void main(void)
{
system("CommandArguments ^\n"); // ^\n does not really pass a line break...
}
The output of LineBreakCommandArguments.exe:
>LineBreakCommandArguments.exe
0: CommandArguments
67 111 109 109 97 110 100 65 114 103 117 109 101 110 116 115
As shown above, CommandArguments got only one argument. The line-break character was missing.
So the question is, how should I modify LineBreakCommandArguments, such that CommandArguments will get the line-break character as an argument?
Note that I still would like to use the system
function, since I want the ability to use shell commands like dir
/cd
, which are not available when using CreateProcess
.
Update:
The reason of asking is that I'm implementing an API for a programming language (haxe). The API allows users to pass arbitrary command to the shell. I hope people wouldn't need to use line breaks in any argument, but who knows... Anyway, since an api for a programming lang is the basis for potentially a lots of programs, I want it to cover as many cases as possible. If it is not feasible to support line breaks in argument, I will document it as is.