execlp example, trying to do system call a bit more securely for Windows and Unix-like OS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifdef _WIN32 | |
#include <process.h> | |
#else | |
#include <unistd.h> | |
#endif | |
int main(void) | |
{ | |
int r; | |
#ifdef _WIN32 | |
intptr_t ir = _execlp("cmd", "cmd", "/c", "dir", NULL); | |
r = (int)ir; | |
#else | |
r = execlp("ls", "ls", ".", NULL); | |
#endif | |
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