added run() for ExecuteCmd, which returns pid of the child process
This commit is contained in:
parent
3ceb311a32
commit
6eae743582
2 changed files with 37 additions and 25 deletions
|
@ -113,7 +113,18 @@ ExecuteCmd::ExecuteCmd(const std::string &cmd, int screen_num):m_cmd(cmd), m_scr
|
|||
|
||||
void ExecuteCmd::execute() {
|
||||
#ifndef __EMX__
|
||||
if (! fork()) {
|
||||
run();
|
||||
#else // __EMX__
|
||||
spawnlp(P_NOWAIT, "cmd.exe", "cmd.exe", "/c", m_cmd.c_str(), static_cast<void*>(NULL));
|
||||
#endif // !__EMX__
|
||||
|
||||
}
|
||||
|
||||
int ExecuteCmd::run() {
|
||||
pid_t pid = fork();
|
||||
if (pid)
|
||||
return pid;
|
||||
|
||||
std::string displaystring("DISPLAY=");
|
||||
displaystring += DisplayString(FbTk::App::instance()->display());
|
||||
char intbuff[64];
|
||||
|
@ -134,11 +145,8 @@ void ExecuteCmd::execute() {
|
|||
putenv(const_cast<char *>(displaystring.c_str()));
|
||||
execl("/bin/sh", "/bin/sh", "-c", m_cmd.c_str(), static_cast<void*>(NULL));
|
||||
exit(0);
|
||||
}
|
||||
#else // __EMX__
|
||||
spawnlp(P_NOWAIT, "cmd.exe", "cmd.exe", "/c", m_cmd.c_str(), static_cast<void*>(NULL));
|
||||
#endif // !__EMX__
|
||||
|
||||
return pid; // compiler happy -> we are happy ;)
|
||||
}
|
||||
|
||||
ExportCmd::ExportCmd(const std::string& name, const std::string& value) :
|
||||
|
|
|
@ -37,6 +37,10 @@ class ExecuteCmd: public FbTk::Command {
|
|||
public:
|
||||
ExecuteCmd(const std::string &cmd, int screen_num = -1);
|
||||
void execute();
|
||||
/**
|
||||
* same as execute but returns pid
|
||||
*/
|
||||
int run();
|
||||
private:
|
||||
std::string m_cmd;
|
||||
const int m_screen_num;
|
||||
|
|
Loading…
Reference in a new issue