-/*
- * use this when execing a command to have it on the right screen
- string dtmp = (string)"DISPLAY=" + display_name;
- if (putenv(const_cast<char*>(dtmp.c_str()))) {
- cout << "warning: couldn't set environment variable 'DISPLAY'\n";
- perror("putenv()");
- }
- */
+
+void screen::execCommand(const std::string &cmd) const {
+ pid_t pid;
+ if ((pid = fork()) == 0) {
+ extern char **environ;
+
+ char *const argv[] = {
+ "sh",
+ "-c",
+ const_cast<char *>(cmd.c_str()),
+ 0
+ };
+ // make the command run on the correct screen
+ if (putenv(const_cast<char*>(_info->displayString().c_str()))) {
+ cout << "warning: couldn't set environment variable 'DISPLAY'\n";
+ perror("putenv()");
+ }
+ execve("/bin/sh", argv, environ);
+ exit(127);
+ } else if (pid == -1) {
+ cout << _epist->getApplicationName() <<
+ ": Could not fork a process for executing a command\n";
+ }
+}