捕获Expect脚本的特定输出

时间:2013-03-08 16:52:56

标签: php telnet expect tasklist

我正在尝试使用Expect确定应用程序RA-POS是否在Mac上运行在远程Windows XP上。我通过PHP页面发送此信息,希望在该页面上返回结果作为初始测试。不幸的是,当我全部运行它们时,结果是命令行提示符,而不是有关程序是否正在运行的实际信息。最后我想创建一个条件,其中expect根据RA-POS是否正在运行返回值1或0,然后继续到另一个脚本或停止该过程。

这是期望

#!/usr/bin/expect -d

set login "administrator"
set password "password"
set machineid [lindex $argv 0]
set portid [lindex $argv 1]
set cmdprompt "C:\Documents and Settings\Administrator>"
set output $expect_out(0,string)

spawn telnet -l administrator $machineid.noerrpole.com $portid
expect "password:"
send "$password\r"
expect "$cmdprompt"
send "tasklist /nh /FI \"IMAGENAME eq RA-POS.exe\"\r"
expect -re "(INFO:*)\r"
send_user "$expect_out(0,string)\n"
expect "$cmdprompt"
send "exit\r"
interact

这是PHP

<?php
echo "<html>";
echo "<head>";
echo "<title>Turn off Windows Automatic Update</title>";
echo "</head>";
echo "<body>";
echo '<img src="NOERRlogofinal.jpg">';
echo "<br>";
echo "<br>";
echo "<pre>";

$portoffset = 1000 * $_POST["station"];
$port = 21023 + $portoffset;
$mall = $_POST["mall"];

$cmd = "/usr/bin/expect /home/dev/www/RAPOStest " . $_POST["mall"] . " " . $port;


echo "Running " . $cmd;

$retval = system($cmd);
echo "<br>";
echo "sss <br>";
echo "$retval";
echo "sss <br>";




echo "</pre>";

echo "<br>Your POS has been updated " . $_POST["mall"];
echo "<br>";
echo "<br>";
echo "</body>";
echo "</html>";

这是输出......

Running /usr/bin/expect /home/dev/www/RAPOStest NPCO-CP 22023spawn telnet -l administrator NPCO-CP.noerrpole.com 22023
Trying 166.161.172.106...

Connected to NPCO-CP.noerrpole.com.

Escape character is '^]'.

Welcome to Microsoft Telnet Service 


password: 

*===============================================================
Welcome to Microsoft Telnet Server.
*===============================================================
C:\Documents and Settings\Administrator>tasklist /nh /FI "IMAGENAME eq RA-POS.exe"
INFO: No tasks running with the specified criteria.

C:\Documents and Settings\Administrator>password:

sss 
C:\Documents and Settings\Administrator>password:sss 

Your POS has been updated NPCO-CP

0 个答案:

没有答案