Re: [Cppcms-users] cppcms::service and system(..)
Brought to you by:
artyom-beilis
From: kpeo <sla...@ya...> - 2012-07-18 11:42:35
|
Hello, Fast answer: system() is not so thread-safe way for calling system scripts. E.g., you can use booster::aio::deadline_timer (async_wait method) or simple "old" pipe-method like this: # define MAX_BUFFER 1024 std::string vexec(std::string const &cmd) { char buf[MAX_BUFFER]; std::string out; FILE* pipe = popen(cmd.c_str(), "r" ); if (pipe == NULL ) { BOOSTER_LOG(debug,__FUNCTION__) << "invoking " << cmd << " is failed"; return ""; } while(1) { fgets(buf, MAX_BUFFER, pipe) != NULL ) { out.append(buf); } pclose(pipe); return out; } Shure, this realisation needs in implementing of timeout for waiting of answer. Regards, kpeo 18.07.2012, 15:03, "Christian Gmeiner" <chr...@gm...>: > Hi all, > > I would like to implement a Service class based on cppcms::service. I would like > to trigger the rpc call via java script (works) and in the Service > class I would like > to use system() function to execute a bash script. > > If after executing/while executing the system function the cppcms apps > hangs completely. > My Service implements also a RPC call which does a reboot of the > system - which works. > > Any idea what could went wrong? > > thanks > --- > Christian Gmeiner, MSc > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users |