Jump to content

Passing Array Through Exec()


hoopplaya4

Recommended Posts

Hi All,

 

I'm trying to pass an array using exec(), but I am not able to display the array.

 

Here's what I am using:

<?php

$arrayhere = array("1","2","3"); 

exec("php testarray.php $arrayhere > /home/public_html/logs/test.php &");

 

Then the "testarray.php" page has this:

 

<?php
$id = $argv[1];

foreach ($id as $value) {

echo $value;

}

 

And, when I look at the results, the following error is printed:

 

Warning: Invalid argument supplied for foreach() in /home/coachser/public_html/testarray.php on line 9

 

Any ideas why it wouldn't be displaying the array?

Link to comment
https://forums.phpfreaks.com/topic/146402-passing-array-through-exec/
Share on other sites

Thanks for the reply.

 

So, now, when attempting to serialize, for some reason, the exec() does not even take place.  This is my new code:

<?php
$arrayhere = array("1","2","3"); 

$newarray = serialize($arrayhere);

exec("php testarray.php $newarray > /home/coachser/public_html/logs/newtest.php &");

 

It's not even creating the "newtest.php" file.  But, I found that when I remove the $newarray from the

exec("php testarray.php...

portion, then it creates the "newtest.php" file.  Any idea what I'm doing wrong here?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.