--- psi-0.10-test2.original/src/chatdlg.cpp 2005-09-04 22:13:18.000000000 +0200 +++ psi-0.10-test2/src/chatdlg.cpp 2005-09-04 22:14:50.000000000 +0200 @@ -882,6 +882,57 @@ return; } +#ifndef Q_WS_WIN + if (d->mle->text().startsWith(QString("/exec "))) { + + QString command = d->mle->text().remove(0, 6).stripWhiteSpace(); + + if (command.isEmpty()) { + d->mle->setText(QString("")); + this->appendSysMsg("/exec: missing command"); + return; + } + + // ** For debugging only: + //fprintf(stderr, "/exec: \"%s\"\n", (const char*)command); + + // This "echo | " prevents freeze when programs expect stdin (for example `cat`) + FILE *fpipe = popen((const char*)(QString("echo | ") + command), "r"); + if (fpipe != NULL) { + + QString result = ""; + + while (!feof(fpipe)) { + + char c[1024]; + memset(c, 0, 1024); + fread(&c, 1023, 1, fpipe); + result += c; + + } + + pclose(fpipe); + + d->mle->setText(result.stripWhiteSpace()); + + if (d->mle->text().isEmpty()) { + this->appendSysMsg("/exec: no output"); + return; + } + + } else { + d->mle->setText(QString("")); + this->appendSysMsg("/exec: failed to exec process"); + return; + } + + } + + // //exec .... -> /exec .... + if (d->mle->text().startsWith(QString("//exec "))) + d->mle->setText(d->mle->text().remove(0, 1)); +#endif + Message m(d->jid); m.setType("chat"); m.setBody(d->mle->text());