Closed denisdemaisbr closed 9 months ago
I don't think you can change the behaviour of #exec
itself, but you could always wrap it in another macro:
#define aexec(x) "#exec x
#define myexec(x) aexec(x)"
int main(void) {
const char *date = myexec(date -R);
return 0;
}
This would result in:
$ gpp -x test.c
int main(void) {
const char *date = "Wed, 14 Dec 2022 10:35:03 +0100
";
return 0;
}
Note that a newline appears within the quotes because date
itself prints a newline. I suspect that there is no way of stripping the newline using GPP (meta)macros; you might need to do this by rewriting the command line to be executed. For example:
const char *date = myexec(date -R | tr -d '\\\n');
hi all. is possible make a result of #exec quoted + terminate statement line ?
--- input --- int main(void) { const char uuid = #exec uuid const char date = #exec date -R return 0; }
--- output --- int main(void) { const char uuid = "a9403e0f-6717-481d-9971-2f41cdfd0a88"; const char date = "Sun, 11 Dec 2022 14:40:16 -0300"; return 0; }
$uuidgen a9403e0f-6717-481d-9971-2f41cdfd0a88
$date -R Sun, 11 Dec 2022 14:40:16 -0300