sajal
sajal

Reputation: 69

c++ equivalent for php shell_exec

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}");

Upvotes: 1

Views: 1394

Answers (2)

Shafik Yaghmour
Shafik Yaghmour

Reputation: 158599

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);
}

Upvotes: 1

Gandras
Gandras

Reputation: 23

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

Upvotes: 0

Related Questions