RE: [PHP] Passing an array to a C program from a php script??
Here is a solution I've found for my problem. I use join to convert my array into a string. Then, I use exec to run the c program, having a pipe passing the result from an echo. I would like to know if this solution is a good one (in term of speed, security...), and would appreciate your comments. Thanks. Nicolas Here is a short example : // Initialize the array $ary_test = array(15, 150, 32, 46, 69, 40, 22); // Convert it to a string $str_test = join(' ', $ary_test); // Execute the c program exec("echo \"$str_test\" | test1", $ary_result, $num_return); // Display the return value and the result of the program echo "Return value : $num_return\n"; echo "Result :\n"; print_r($ary_result); -Message d'origine- De : Nicolas Guilhot [mailto:[EMAIL PROTECTED]] Envoye : lundi 25 juin 2001 12:59 A : [EMAIL PROTECTED] Objet : [PHP] Passing an array to a C program from a php script?? Hi all, I have a big array (nearly 1000 lines) that I would like to pass to a C program. I don't want to create a temporary file to pass my array (If possible ?!?), and I don't think the command line will fit my needs. Is there a way to execute a program with a php string as the standard input. Something like shell redirection 'c_program < input.file' but with input.file being a php variable and not a real file ?? Any other solution ?? Hope I am clear enough ! Any help would be appreciated. Nicolas -- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Passing an array to a C program from a php script??
> I have a big array (nearly 1000 lines) that I would like to pass to a C > program. I don't want to create a temporary file to pass my array (If > possible ?!?), and I don't think the command line will fit my needs. > > Is there a way to execute a program with a php string as the standard > input. Something like shell redirection 'c_program < input.file' but with > input.file being a php variable and not a real file ?? Any other solution > ?? 2 choices: #1 (for the real hacker geek) Compile your C program *into* PHP as a function, using the PEAR stuff. You may need to use PHP's http://php.net/serialize function to turn your array into a giant string and write a C routine to unserialize it, or, by the time you get done converting your program to PEAR, it will just accept your PHP array as an argument. #2 (pretty slick, though...) Run your C program using http://php.net/psockopen and use http://php.net/fputs to spew your data at it one line at a time. -- WARNING [EMAIL PROTECTED] address is an endangered species -- Use [EMAIL PROTECTED] Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm Volunteer a little time: http://chatmusic.com/volunteer.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Passing an array to a C program from a php script??
> Hi all, > > I have a big array (nearly 1000 lines) that I would like to pass to a C > program. I don't want to create a temporary file to pass my array (If > possible ?!?), and I don't think the command line will fit my needs. > > Is there a way to execute a program with a php string as the standard > input. Something like shell redirection 'c_program < input.file' but with > input.file being a php variable and not a real file ?? Any other solution > ?? > > Hope I am clear enough ! what you can do is serialize the array and then parse it with you c-program (it is not very difficult, to get the syntax ;-) ): popen($fh,"|my_c_program"); pwrite($fh,$serialized_array); pclose($ph); (hope that was what you were asking) michi -- GMX - Die Kommunikationsplattform im Internet. http://www.gmx.net -- GMX Tipp: Machen Sie Ihr Hobby zu Geld bei unserem Partner 1&1! http://profiseller.de/info/index.php3?ac=OM.PS.PS003K00596T0409a -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Passing an array to a C program from a php script??
> I have a big array (nearly 1000 lines) that I would like to pass to a C > program. I don't want to create a temporary file to pass my array (If > possible ?!?), and I don't think the command line will fit my needs. > > Is there a way to execute a program with a php string as the standard > input. Something like shell redirection 'c_program < input.file' but with > input.file being a php variable and not a real file ?? Any other solution > ?? If your PHP script outputs to stdout, then you could run: c_program < myscript.php Your PHP script will need to output the array as if it were outputting to the screen or web page (ie, echo/print), and your C program will need to know what format it's coming in as. Jason -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Passing an array to a C program from a php script??
Why not make a separate .txt file which is read by the PHP script to make its variable with file(), and have the C file read it with ifstream to make up its variable? --Jason -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]