hoopplaya4 Posted January 14, 2009 Share Posted January 14, 2009 Hey All, I'm trying to pass a PHP variable to another PHP script via Exec(). I am using Exec because I want to run the script in the background to do some processing. Here's what I currently have: $id=$_POST['name']; exec("php myscript.php?name=" . $id . " >> completed.php &"); Now, when I manually browse to the PHP script and run it, it works fine, however, it doesn't work when I try to "exec" it. It appears that the $id isn't passing. Is there something I'm doing wrong here? Or is there another way to pass the variable? Thanks! Link to comment https://forums.phpfreaks.com/topic/140875-solved-pass-a-php-variable-to-exec/ Share on other sites More sharing options...
flyhoney Posted January 14, 2009 Share Posted January 14, 2009 exec("php myscript.php $id >> completed.php &"); Should work. And to get id in myscript.php: $id = $argv[0]; Link to comment https://forums.phpfreaks.com/topic/140875-solved-pass-a-php-variable-to-exec/#findComment-737354 Share on other sites More sharing options...
hoopplaya4 Posted January 14, 2009 Author Share Posted January 14, 2009 Thanks for the reply, flyhoney. That got me further, but now, it's actually passing "myscript.php" as the variable, not $_POST['name']. Link to comment https://forums.phpfreaks.com/topic/140875-solved-pass-a-php-variable-to-exec/#findComment-737360 Share on other sites More sharing options...
hoopplaya4 Posted January 15, 2009 Author Share Posted January 15, 2009 Nevermind, got it figured out! Used "$argv[1];" instead! Thanks again! Link to comment https://forums.phpfreaks.com/topic/140875-solved-pass-a-php-variable-to-exec/#findComment-737362 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.