从期望脚本中的交互返回

时间:2015-01-21 17:32:20

标签: tcl expect

我正在使用DAOMATCH,一个天文程序来查找图像之间的匹配,我试图用EXPECT对其进行半自动化。

该程序要求输入一些输入,如果失败,他会询问我是否要保留转换。这就是为什么我想半自动化它:我想自动给他输入,但是当"写这个转换"问题出来了,我想对程序有所控制权。为此,我已经编写了(初学者用TCL)这段代码

#!/usr/bin/expect -D

set timeout 1

spawn "~/myDaophot/daophot4/daomatch"
expect "*Master*"
send "060326T034700403_4.als\r"
expect "*Output*"
send "060326T002448794_2_4.mch\r"
expect "*input*" {send "060326T034700403_2.als\r"}
expect "*transformation*" {interact -o "y\r" {return}}
expect "*input*" {send "060326T034519602_4.als\r"}
expect "*transformation*" {interact -o "y\r" {return}}
expect "*input*" {send "060326T034519602_2.als\r"}
expect "*transformation*" {interact -o "y\r" {return}}
expect "*input*" {send "060326T002627552_4.als\r"}
expect "*transformation*" {interact -o "y\r" {return}}
expect "*input*" {send "060326T003255953_2.als\r"}
expect "*transformation*" {interact -o "y\r" {return}}
expect "*input*" {send "060326T003521749_2.als\r"}
#Question pops up here!!!
expect "*transformation*" {interact -o "y\r" {return}}
#-o needed, otherwise daomatch stops...
#\r needed otherwise, with "y" only, daomatch stops
expect "*input*" {send "060326T002539353_4.als\r"}
expect "*transformation*" {interact -o "y\r" {return}}
#other inputs.....

现在,这个问题在我将其标记为评论之前不会弹出(仅仅因为这是第一个坏图像)。我用键盘给你,\ r \ n。 DAOMATCH一直工作直到这个命令:我知道这是因为,在输出中,我找到了所有的变换,包括我回答的最后一个变换" y \ r"。

然而,在这一点上,这就是发生的事情

 060326T003521749_2.als           -48    33   0.999   0.010  -0.010   0.999   0.95

         3    0.805    0.000    0.000    0.020    0.012
         2    2.000    2.000    0.400    0.500
 WT  0.804957092  <    2

                        Write this transformation? 

                    Next input file (default EXIT): zaamus@zaamuspc:~/Documenti/Fits/GCs/Omega_Cen$

所以,最后的期望没有被执行。我试图改变超时,改变返回到inter_return,但我仍然没有解决这个问题。

我知道这里有一些类似的问题,但是我无法将期望封装在交互中,因为在失败的那个之后我还有50-60个输入。

1 个答案:

答案 0 :(得分:0)

没关系......我找到了解决方案:我必须在#!/ usr / bin / expect

中添加-c
#!/usr/bin/expect -c

set timeout 1

spawn "~/myDaophot/daophot4/daomatch"

expect "*Master*" {send "060326T034700403_4.als\r"}
expect "*Output*" {send "060326T002448794_2_4.mch\r"}
expect "*input*" {send "060326T034700403_2.als\r"}
expect "*transformation*" {interact -o y\r {return} n\r {return}}
expect "*input*" {send "060326T034519602_4.als\r"}
expect "*transformation*" {interact -o y\r {return} n\r {return}}
expect "*input*" {send "060326T034519602_2.als\r"}
expect "*transformation*" {interact -o y\r {return} n\r {return}}
expect "*input*" {send "060326T002627552_4.als\r"}
expect "*transformation*" {interact -o y\r {return} n\r {return}}
expect "*input*" {send "060326T003255953_2.als\r"}
expect "*transformation*" {interact -o y\r {return} n\r {return}}
expect "*input*" {send "060326T003521749_2.als\r"}
expect "*transformation*" {interact -o y\r {return} n\r {return}}
expect "*input*" {send "060326T002539353_4.als\r"}
expect "*transformation*" {interact -o y\r {return} n\r {return}}
expect "*input*" {send "060326T002627552_2.als\r"}
expect "*transformation*" {interact -o y\r {return} n\r {return}}
expect "*input*" {send "060326T002715751_4.als\r"}
expect "*transformation*" {interact -o y\r {return} n\r {return}}
expect "*input*" {send "060326T002539353_2.als\r"}
expect "*transformation*" {interact -o y\r {return} n\r {return}}
expect "*input*" {send "060326T034457403_4.als\r"}
expect "*transformation*" {interact -o y\r {return} n\r {return}}

有一件事:我知道期望有一个非常严格的语法,但只有我在那里写的方式才能进行交互。如果我尝试添加像这样的括号

interact -o {y\r {return} n\r {return}}

它不起作用。