1 #include <Poco/Environment.h>
2 #include <Poco/Process.h>
34 if (chdir(homeDir_.c_str())==0)
78 catch(Poco::Exception& e)
89 Poco::Timestamp tsStart;
111 catch(Poco::Exception& e)
117 catch(std::exception& e)
126 outputMessage.
setTime(timeInterval);
127 resultDataItem.
setTime(timeInterval);
129 resultData.
addDataItem(std::forward<DRCEResultDataItem>(resultDataItem));
131 std::string resultJson;
133 if (!resultDataSerializator.
serialize(resultJson))
136 outputMessage.
setData(resultJson);
138 return outputMessage;
141 std::string DRCEFunctionalObject::getFullFileName(
const std::string&
fileName)
144 if (fileName.find_last_of(
'/')==std::string::npos)
145 result.append(
"./").append(fileName);
154 const size_t filesCount = filesList.getFilesCount();
155 for (
size_t i=0;i<filesCount;++i)
157 const std::string fileName = getFullFileName(filesList.getFileItem(i).name);
161 std::fstream ofs(fileName.c_str(), std::fstream::out|std::fstream::trunc|std::fstream::binary);
170 if (
remove(fileName.c_str())!=0)
180 const size_t filesCount = filesList.getFilesCount();
181 for (
size_t i=0;i<filesCount;++i)
183 const std::string fileName = getFullFileName(filesList.getFileItem(i).name);
188 ifs.open(fileName, std::fstream::binary);
189 if ( (ifs.rdstate() & std::ifstream::failbit ) != 0 )
192 std::string fileContent;
193 ifs.seekg(0, std::ios::end);
194 fileContent.resize(ifs.tellg());
195 ifs.seekg(0, std::ios::beg);
196 ifs.read(const_cast<char*>(fileContent.c_str()), fileContent.size());
200 fileItem.
actionType = filesList.getFileItem(i).actionType;
201 fileItem.
name = filesList.getFileItem(i).name;
203 resultDataItem.addFileItem(std::forward<FileItem>(fileItem));
207 if (
remove(fileName.c_str())!=0)
217 for (
size_t i=0;i<enviroments.size();++i)
219 if (setenv(enviroments[i].first.c_str(), enviroments[i].second.c_str(), 0)!=0)
224 void DRCEFunctionalObject::applyInputStream(std::stringstream& cmd, std::stringstream& istr)
226 std::istream_iterator<std::string> eos;
227 std::istream_iterator<std::string> iit(istr);
242 makeFilesBefore(inputJsonMessage);
244 makeSetEnviroment(inputJsonMessage.getSessionOptions().environments);
246 std::stringstream cmd, istr(inputJsonMessage.getInputStream()), ostr, estr;
247 if (!istr.str().empty())
249 if (inputJsonMessage.getCommandLine().empty())
252 applyInputStream(cmd, istr);
255 if (!inputJsonMessage.getCommandLine().empty())
257 cmd << inputJsonMessage.getCommandLine();
261 if (!shellExec.exec(ostr, estr))
268 resultDataItem.setExitStatus(shellExec.getExitStatus());
271 resultDataItem.setStdoutStream(ostr.str());
272 resultDataItem.setStderrStream(estr.str());
273 resultDataItem.setNodeName(
nodeName);
275 makeFilesAfter(inputJsonMessage, resultDataItem);