note 35910 added to ref.exec

From: Date: Thu, 18 Sep 2003 19:41:24 +0000
Subject: note 35910 added to ref.exec
Groups: php.notes 
Request: Send a blank email to php-notes+get-56729@lists.php.net to get a copy of this message
I was stuck for about an hour and a half last night trying to get Perl to pass back values to my PHP script after running an exec() command. Since my Perl script was using STDOUT (after being passed command lines variables), I expected the variables used in my .pl script to be accessible in PHP, no questions asked. Of course, this wasn't working and I finally figured it out with the help of a friend (Shawn = superstar): you need to echo the exec() command in order to get the values back into PHP. Since I was returning multiple values, I added pipe delimiters in my .pl script and then used PHP to parse the string to retreive my data into different variables. Check it out: #hit the .pl script with the data $mydata = exec("script.pl 'command line args' "); exec("exit(0)"); #parse the value that comes back from the .pl script list($strA, $strB) = split ('[|]', $mydata); echo "valueA: " . $strA."<br>"; echo "valueB: " . $strB."<br>"; Woo-hoo! /d ---- Manual Page -- http://www.php.net/manual/en/ref.exec.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35910 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35910&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35910&report=yes

« previous php.notes (#56729) next »