Skip to content

Instantly share code, notes, and snippets.

Created February 14, 2023 17:12
What would you like to do?
execlp example, trying to do system call a bit more securely for Windows and Unix-like OS
#ifdef _WIN32
#include <process.h>
#include <unistd.h>
int main(void)
int r;
#ifdef _WIN32
intptr_t ir = _execlp("cmd", "cmd", "/c", "dir", NULL);
r = (int)ir;
r = execlp("ls", "ls", ".", NULL);
if(r != -1)
return 0;
return r;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment