如何在 while 循环中将 运行 "file exist" 函数 (expect/tcl) 作为条件?
How to run "file exist" function (expect/tcl) as condition during a while loop?
我知道这是一个与其他帖子类似的问题,但在尝试了他们代码的变体后,我无法获得我想要的结果。 expect 脚本登录,提交集群作业并等待写入结果文件。我想定期检查结果文件,并在文件位于目录中后继续我的期望脚本。当我 运行 以下代码时, [file exists outgraph.json]
似乎永远不会等于 1
即使我在另一个 ssh 会话中看到该文件。我想我忽略了一些简单的事情,但无法弄清楚为什么它在循环期间从未检测到文件,导致 expect 脚本永远不会前进。
#Attempt 1
#Spawning and logging in
send "qsub -v QUERY=$query run\_query.pbs\r"
while {true} {
after 2000
if {[file exists outgraph.json] == 1} {
break;
}
puts [file exists outgraph.json]
}
expect "$ "
send "rm -rf tmp1\r";
expect "$ "
send "rm input.fa\r";
expect "$ "
send "exit\r"
# moving file with sftp
#Attempt 2
# spawning and logging in
send "qsub -v QUERY=$query run\_query.pbs\r"
set fexist [file exists outgraph.json]
while {$fexist == 0} {
after 2000;
set fexist [file exists outgraph.json]
puts $fexist
}
expect "$ "
send "rm -rf tmp1\r";
expect "$ "
send "rm input.fa\r";
expect "$ "
send "exit\r"
# moving file with sftp
问题是因为file exists
。它检查文件路径存在与否,只在本地机器中,无论你在哪里 运行 Expect
脚本,不在远程目录中。
#This is a common approach for few known prompts
#If your device's prompt is missing here, then you can add the same.
set prompt "#|>|\$ $"; # We escaped the `$` symbol with backslash to match literal '$'
set filename outgraph.json
set cmd "(\[ -f $filename ] && echo PASS) || echo FAIL"
send "$cmd\r"
expect {
"\r\nPASS" { puts "File is available";exp_continue}
"\r\nFAIL" { puts "File is not available";exp_continue}
-re $prompt
}
我知道这是一个与其他帖子类似的问题,但在尝试了他们代码的变体后,我无法获得我想要的结果。 expect 脚本登录,提交集群作业并等待写入结果文件。我想定期检查结果文件,并在文件位于目录中后继续我的期望脚本。当我 运行 以下代码时, [file exists outgraph.json]
似乎永远不会等于 1
即使我在另一个 ssh 会话中看到该文件。我想我忽略了一些简单的事情,但无法弄清楚为什么它在循环期间从未检测到文件,导致 expect 脚本永远不会前进。
#Attempt 1
#Spawning and logging in
send "qsub -v QUERY=$query run\_query.pbs\r"
while {true} {
after 2000
if {[file exists outgraph.json] == 1} {
break;
}
puts [file exists outgraph.json]
}
expect "$ "
send "rm -rf tmp1\r";
expect "$ "
send "rm input.fa\r";
expect "$ "
send "exit\r"
# moving file with sftp
#Attempt 2
# spawning and logging in
send "qsub -v QUERY=$query run\_query.pbs\r"
set fexist [file exists outgraph.json]
while {$fexist == 0} {
after 2000;
set fexist [file exists outgraph.json]
puts $fexist
}
expect "$ "
send "rm -rf tmp1\r";
expect "$ "
send "rm input.fa\r";
expect "$ "
send "exit\r"
# moving file with sftp
问题是因为file exists
。它检查文件路径存在与否,只在本地机器中,无论你在哪里 运行 Expect
脚本,不在远程目录中。
#This is a common approach for few known prompts
#If your device's prompt is missing here, then you can add the same.
set prompt "#|>|\$ $"; # We escaped the `$` symbol with backslash to match literal '$'
set filename outgraph.json
set cmd "(\[ -f $filename ] && echo PASS) || echo FAIL"
send "$cmd\r"
expect {
"\r\nPASS" { puts "File is available";exp_continue}
"\r\nFAIL" { puts "File is not available";exp_continue}
-re $prompt
}