passthru()'s prototype is actually:
void passthru(string cmd[, int &return) http://php.net/passthru
Meaning using passthru() with the concatenation operator . will produce unexpected results, as the product of the passthru call is actually printed directly out to the page, as is. Nothing is returned. If you wish to snag the output of an external command into a variable, or modify it further using another function, consider the backtick operator (`):
$output = `osascript /Library/WebServer...`; printf("Current song: %s\n", $output);
If you have trouble finding the backtick ` -- remember, it's not a single-quote mark, it's a backtick, usually on the ~ key -- system() will accomplish the same thing in a functional fashion. Or, you can keep passthru(), and just use it differently:
Current song: <?php passthru("osascript /Library/WebServer..."); ?>
If this doesn't work, check to make sure osascript is printing to stdout. I'm not sure how osascript works, as I'm not a Mac user, but I'm assuming this is OS X (from the pathnames) -- therefore, I *imagine* there's a stdout on OS X.
passthru() should grab whatever goes to stdout. If it still doesn't work for you, check the page source to see if passthru() drops anything but it's formatted out (hey, I have to say it). Oh, and make sure Apache can run osascript. If Apache can't run osascript, that's another problem. (I would imagine it'd have to be able to access your Applescript file as well.)
Good luck! HTH
Jed
Brian Heibert wrote:
Hi,
I am new to this list. I am trying to do a php script that will say what song is currently playing in iTunes/NiceCast Internet Radio broadcaster Onto my website
Every attempt I have made so far has failed
I got a file called playing.php With this text inside it: <?php
echo "Current Song: ".passthru("osascript /Library/WebServer/Documents/christiantoplist/whattrack.scpt");
?>
And a file called whattrack.scpt (AppleScript file) with this in it tell application "iTunes" set trk to current track set tle to name of trk set art to artist of trk set albm to album of trk return tle & " - " & art & ", " & albm end tell
But it is not displaying what song is playing on my website All it says is Current Song: and then it doesn't say the song
Brian Heibert
PS: I have a iMac G4 800mhz OS 10.3.6 running Apple's webserver system preference which is there version of Apache I think
-- _ (_)___ Jed Smith, Code Ninja | / __| RFBs: [email for info] | \__ \ +1 (541) 606-4145 _/ |___/ jed@xxxxxx (Signed mail preferred: PGP 0x703F9124) |__/ http://personal.jed.bz/keys/jedsmith.asc
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php