c++ equivalent for php shell_exec

ぐ巨炮叔叔 提交于 2019-12-13 18:14:31

问题


What will be the C++ equivalemt command for below mentioned php command:

$command = shell_exec("sqlldr {$connect_string} control={$ctl_file_name} log={$log_file_name}");

回答1:


So based on your comments a solution that would work would be to use popen(3):

#include <cstdio>
#include <iostream>
#include <string>

int main()
{
   // Set file names based on your input etc... just using dummies below
   std::string
     ctrlFileName = "file1",
     logFileName  = "file2",
     cmd = "sqlldr usr/pwd@LT45 control=" + ctrlFileName + " log=" + logFileName ;

   std::cout << "Executing Command: " << cmd << std::endl ;

   FILE* pipe = popen(cmd.c_str(), "r");

   if (pipe == NULL)
   {
     return -1;
   }

   char buffer[128];
   std::string result = "";

   while(!feof(pipe))
   {
     if(fgets(buffer, 128, pipe) != NULL)
     {
         result += buffer;
     }
  }

   std::cout << "Results: " << std::endl << result << std::endl ;

   pclose(pipe);
}



回答2:


Try forkpty, you get a file descriptor which you can use to read from the other pseudoterminal.



来源:https://stackoverflow.com/questions/15136935/c-equivalent-for-php-shell-exec

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!