X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/79f7273499683ed53550ba195ee634cd03f78007..90293e90301f5ef5c224fd08b8cd229982e2f597:/lib/base/console.cpp diff --git a/lib/base/console.cpp b/lib/base/console.cpp index cc994ea9..2e00804a 100644 --- a/lib/base/console.cpp +++ b/lib/base/console.cpp @@ -8,7 +8,7 @@ #include #include -int bidirpipe(int pfd[], const char *cmd , const char * const argv[]) +int bidirpipe(int pfd[], const char *cmd , const char * const argv[], const char *cwd ) { int pfdin[2]; /* from child to parent */ int pfdout[2]; /* from parent to child */ @@ -37,6 +37,9 @@ int bidirpipe(int pfd[], const char *cmd , const char * const argv[]) for (unsigned int i=3; i < 90; ++i ) close(i); + if (cwd) + chdir(cwd); + execvp(cmd, (char * const *)argv); /* the vfork will actually suspend the parent thread until execvp is called. thus it's ok to use the shared arg/cmdline pointers here. */ _exit(0); @@ -79,6 +82,20 @@ static char *find_bracket(char ch) return NULL; } +int eConsoleAppContainer::setCWD( const char *path ) +{ + struct stat dir_stat; + + if (stat(path, &dir_stat) == -1) + return -1; + + if (!S_ISDIR(dir_stat.st_mode)) + return -2; + + m_cwd = path; + return 0; +} + int eConsoleAppContainer::execute( const char *cmd ) { int cnt=0, slen=strlen(cmd); @@ -157,7 +174,8 @@ int eConsoleAppContainer::execute(const char *cmdline, const char * const argv[] killstate=0; // get one read ,one write and the err pipe to the prog.. - pid = bidirpipe(fd, cmdline, argv); + pid = bidirpipe(fd, cmdline, argv, m_cwd.length() ? m_cwd.c_str() : 0); + if ( pid == -1 ) return -3; @@ -333,7 +351,18 @@ void eConsoleAppContainer::write( const char *data, int len ) char *tmp = new char[len]; memcpy(tmp, data, len); outbuf.push(queue_data(tmp,len)); - out->start(); + if (out) + out->start(); +} + +void eConsoleAppContainer::write( PyObject *data ) +{ + char *buffer; + int length; + if (PyString_AsStringAndSize(data, &buffer, &length)) + return; + if (buffer && length) + write(buffer, length); } void eConsoleAppContainer::readyWrite(int what)