我正在尝试确定应用程序 RA-POS 是否正在使用 Expect 的 Mac 在远程 Windows XP 上运行。我通过一个 PHP 页面发送它,希望在该页面上返回结果作为初始测试。不幸的是,当我将它们全部一起运行时,结果是命令行提示,而不是有关程序是否正在运行的实际信息。最终,我想创建一个条件,根据 RA-POS 是否正在运行,expect 返回值 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