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
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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.