写入文件时,预计脚本文件名太长

时间:2016-08-07 00:43:41

标签: tcl expect

我是编码的新手,这是我的第一个脚本。它的工作原理是它必须打开(创建)要写入的文件。然后它失败了一些错误,somepassedNickvariable.txt文件名太长了。我以用户身份运行它" qbot"。

第一个期望的样本输出:

2016-08-05T23:32:42 73600,565 INF Chat: 'Quadro': !ustawdomek

第二个示例输出:

1. id=51890, Pepesza, pos=(473,1, 42,1, 1223,7), rot=(-66,1, 104,1, 0,0), remote=True, health=97, deaths=6, zombies=138, players=1, score=109, level=35, steamid=xxx, ip=xx.xx.xx.xx, ping=111
2. id=1141, Quadro, pos=(465,6, 87,1, -624,1), rot=(-30,9, 1620,0, 0,0), remote=True, health=187, deaths=1, zombies=525, players=0, score=520, level=84, steamid=xxx, ip=xx.xx.xx.xx, ping=24
Total of 6 in the game

任何帮助都会非常感激,因为我无法独自完成工作。

#!/usr/bin/expect
set timeout -1
spawn telnet localhost 8081
expect "Please enter password" {sleep 3; send "blahblah\r" }

while {1} {
expect \
{
  "*INF Chat: '*': !ustawdomek" {
            regexp {'(.+)':\s\!ustawdomek} $expect_out(buffer) match Nick;
            set listplayers "*Total of * in the game";
            send "lp\r"
            expect $listplayers {
regexp "$Nick\,\\spos\=\\(\(\(\[-\]\?\\d+\)\,\\d\,\\s\(\[-\]\?\\d+\)\,\\d\,\\s\(\[-\]\?\\d+\)\,\\d\)\\)" $expect_out(buffer) match lok lok1 lok2 lok3
                    set file [open "/home/qbot/domki/$Nick.txt" w]
                    puts $file "$lok1 $lok2 $lok3"
                    close $file
                    send "pm $Nick \"\[QBOT\]Blahblah\"\r" }

             }
   timeout {break}
   eof {break}
}
}

1 个答案:

答案 0 :(得分:0)

我不完全理解这个脚本的语法。但我想这与regexp {'(.+)':\s\!ustawdomek} $expect_out(buffer) match Nick;有关 .+因此是一个贪婪的正则表达式,应尽可能避免。我认为它试图匹配一个非常大的文件名。尝试使用更简单的正则表达式,只允许单词匹配,并可能限制文件名的大小。例如,\w{1,25}或类似的东西。

相关问题