Created
April 5, 2012 08:15
-
-
Save a-square/2308949 to your computer and use it in GitHub Desktop.
A program that allows you to run gui apps from the console without getting all of its output. E.g.: cd ~/work/a/b/c/; run ./gui-app param
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
#include <unistd.h> | |
#include <sys/types.h> | |
#include <sys/ioctl.h> | |
int main (int argc, char **argv) | |
{ | |
pid_t pid; | |
int fd; | |
/* | |
* parent terminates | |
* child gets rid of its tty and then shift-runs its arguments | |
*/ | |
pid = fork(); | |
if (pid < 0) { | |
return 1; | |
} else if (pid == 0) { | |
/* close standard files */ | |
close (0); close (1); close (2); | |
/* detach the tty */ | |
fd = open ("/dev/tty", 0); | |
ioctl (fd, TIOCNOTTY); | |
close (fd); | |
/* execute the provided program */ | |
execvp (argv[1], argv + 1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment