pass PHP $variable to expect

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sheldon
Forum Newbie
Posts: 2
Joined: Wed Aug 05, 2009 11:19 pm

pass PHP $variable to expect

Post by sheldon »

Anyone know how to pass a variable known in my php code to an expect script? here's a slimmed down version of what I have...

PHP

Code: Select all

 
<?php
$address = "192.168.0.1";
print("trying to pass $address to the expect script");
print("<br/>");
exec("expect telnet.exp $address");
print("<br/>see if it worked");
?>
 


Expect (tcl)

Code: Select all

 
#! /usr/bin/expect -f
set timeout 20
set address [lindex $argv 0]
log_file log.txt
spawn telnet $address
close
 
Thanks in advance!
towerspl
Forum Newbie
Posts: 20
Joined: Mon Aug 03, 2009 7:37 am

Re: pass PHP $variable to expect

Post by towerspl »

no idea about that but sounds like a soap kind of thing


or maybe a very hacky file_get_contents("http://www.othersite.com/otherscript.php?variable=" . $variabletopass)
sheldon
Forum Newbie
Posts: 2
Joined: Wed Aug 05, 2009 11:19 pm

Re: pass PHP $variable to expect

Post by sheldon »

Thanks for the help. As it turns out I wasn't having a problem passing the variable from php to expect, I wasn't getting the variable from JS to PHP. I've corrected it and the code I posted works. Cheers!
Post Reply