summaryrefslogtreecommitdiffstats
path: root/lib/Plugins/RunApp.cpp
diff options
context:
space:
mode:
authorZdenek Prikryl <zprikryl@redhat.com>2009-03-19 14:30:51 +0100
committerZdenek Prikryl <zprikryl@redhat.com>2009-03-19 14:30:51 +0100
commit0da04fa121546f9f8f05436e898f988830a27261 (patch)
treed10d36c3bfaf08e4f679fa1396c3700b5c300238 /lib/Plugins/RunApp.cpp
parentd698cf9bca1ac7f5c1a989161ea959a895900273 (diff)
downloadabrt-0da04fa121546f9f8f05436e898f988830a27261.tar.gz
abrt-0da04fa121546f9f8f05436e898f988830a27261.tar.xz
abrt-0da04fa121546f9f8f05436e898f988830a27261.zip
new action plugin
Diffstat (limited to 'lib/Plugins/RunApp.cpp')
-rw-r--r--lib/Plugins/RunApp.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/lib/Plugins/RunApp.cpp b/lib/Plugins/RunApp.cpp
new file mode 100644
index 0000000..dc0059d
--- /dev/null
+++ b/lib/Plugins/RunApp.cpp
@@ -0,0 +1,70 @@
+/*
+ RunApp.cpp
+
+ Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com)
+ Copyright (C) 2009 RedHat inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+
+#include "RunApp.h"
+#include <stdio.h>
+#include "DebugDump.h"
+
+#define COMMAND 0
+#define FILENAME 1
+
+void CActionRunApp::ParseArgs(const std::string& psArgs, vector_args_t& pArgs)
+{
+ std::string::size_type ii_old = 0, ii_new = 0;
+ ii_new = psArgs.find(",");
+ while (ii_new != std::string::npos)
+ {
+ pArgs.push_back(psArgs.substr(ii_old, ii_new - ii_old));
+ ii_old = ii_new + 1;
+ ii_new = psArgs.find(",",ii_old);
+ }
+ pArgs.push_back(psArgs.substr(ii_old));
+}
+
+void CActionRunApp::Run(const std::string& pDebugDumpDir,
+ const std::string& pArgs)
+{
+ char line[1024];
+ std::string output = "";
+
+ vector_args_t args;
+
+ FILE *fp = popen(args[COMMAND].c_str(), "r");
+ if (fp == NULL)
+ {
+ throw "CActionRunApp::Run(): cannot execute " + args[COMMAND];
+ }
+ while (fgets(line, 1024, fp) != NULL)
+ {
+ output += line;
+ }
+ pclose(fp);
+
+ if (args.size() > 1)
+ {
+ CDebugDump dd;
+ dd.Open(pDebugDumpDir);
+ dd.SaveText(args[FILENAME], output);
+ dd.Close();
+ }
+
+}