I am calling executable file with main() function from php script using exec(). Which works fine but return all printf() values rather only returning array:
main.cpp:
#include<stdio.h>
#include<string.h>
#include "foo.h"
int main(int argc, char *argv[] )
{
char buffer[1024];
char *ch;
static int ar[2];
strcpy(buffer,argv[1]);
printf("Client :
");
if ( argc != 2 ) /* argc should be 2 for correct execution */
{
printf( "
%s filename
", argv[0] );
}
else
{
printf("
string is :%s
",buffer);
ch=foo(buffer);
ar[0]=((int*)ch)[0];
ar[1]=((int*)ch)[1];
printf("Counts is :%d %d
",ar[0],ar[1]);
}
return (int)ar;
}
my test.php
<?php
$s="critic worst";
escapeshellarg($s);
$a=array(shell_exec('/home/technoworld/Videos/LinSocket/client "nice bad"'));
print_r($a[0]);
//echo exec('whoami');
?>
Which shows output:
Client : string is :nice bad Positive count: 2 Negative count: 2 array item2 2 Count is :2 2
I also tried with exec() which also gives same prob. Can any one suggest how to get ar[0] and ar[1] from main.cpp?
Client : string is :nice bad Positive count: 2 Negative count: 2 array item2 2
This is from all printf() present in foo.cpp file.
When I use exec() then it gives Count is :2 2
How to get exact ar[0] and ar[1]