1

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}");
alestanis
  • 21,519
  • 4
  • 48
  • 67
sajal
  • 69
  • 1
  • 13
  • If you want to execute some shell command with C++ try to take a look to http://stackoverflow.com/questions/7207916/execute-shell-commands-using-popen-in-c – Mihai8 Feb 28 '13 at 13:40
  • if you want to use PHP, use PHP. If you want c++, use c++ code. For calling shell in c++ you can most likely use `system()` but this wont give you a string back. I am 99% sure there is a c++ library/implementation/ADO-Provider doing this way better. – Najzero Feb 28 '13 at 14:01
  • I think this tread which shows how to use popen may be your answer http://stackoverflow.com/questions/478898/how-to-execute-a-command-and-get-output-of-command-within-c – Shafik Yaghmour Feb 28 '13 at 14:09
  • Thanks @ShafikYaghmour . Got the code what exactly I was looking for.But now I am getting this error: LRM-00116: syntax error at 'log' following '=' SQL*Loader-100: Syntax error on command-line. Command used by me : "sqlldr usr/pwd@LT45 control=ctrl_file log=log_file" – sajal Mar 01 '13 at 11:31
  • @sajal that is a Oracle error, please see Oracle's site for details on error message code for example this covers SQL*Loader-100 for Oracle8: http://docs.oracle.com/cd/A58617_01/server.804/a58312/newch71.htm If you are still having trouble getting the sqlldr part to work I would suggest a second question for that. I also provided an answer based on your response below. – Shafik Yaghmour Mar 01 '13 at 13:40

2 Answers2

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);
}
Shafik Yaghmour
  • 154,301
  • 39
  • 440
  • 740
0

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

Gandras
  • 23
  • 3