在 Windows 7 中使用 ActiveTcl 8.5 在 tcl 脚本中运行 DOS 命令或批处理文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7604286/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 18:11:05 来源:igfitidea点击:
Running DOS command or batch file in tcl script in Windows 7 with ActiveTcl 8.5
提问by action
The following is the tcl code.
以下是tcl代码。
#!/bin/sh
# \
exec tclsh "couldn't execute "C:\Windows\System32\cmd.exe \c dir": no such file or directory
while executing
"exec [auto_execok dir]"
(file "mytst.tcl" line 35)
" ${1+"$@"}
package require Expect
package require log
source [file join [info library] init.tcl]
set exp::winnt_debug 1
log::lvChannel debug stdout
log::log debug "debug msg ON\r"
set env(TERM) dumb
array set OPTS {
host ""
user ""
passwd ""
login telnet
prompt "(%|#|>|\$) $"
ls "/bin/ls -A1"
}
set xlpad "yahoo.com"
exec [auto_execok dir]
while {1} {
spawn ping $xlpad
set loss 0
set replya 0
for { set pingc 0 } { $pingc < 3 } { incr pingc 1} {
expect {
"timed out" {
incr loss 1
puts "intercepted time out message: $loss\n"
}
"Reply" {
incr replya 1
}
}
if { $replya > 2 } {
break
}
}
break
}
return
I got the following messages:
我收到以下消息:
exec {*}[auto_execok dir]
But the ping works ok.
但 ping 工作正常。
回答by glenn Hymanman
auto_execok
returns a list, which is passed to exec
as a single argument. You need to expand the list:
auto_execok
返回一个列表,该列表exec
作为单个参数传递。您需要扩展列表:
% file mkdir tmp
% cd tmp
% close [open test w]
% exec [auto_execok dir]
couldn't execute "C:\WINNT\system32\cmd.exe \c dir": no such file or directory
% exec {*}[auto_execok dir]
Volume in drive D is Data
Volume Serial Number is ....
Directory of d:\glennj\tmp
2011-09-30 10:08 AM <DIR> .
2011-09-30 10:08 AM <DIR> ..
2011-09-30 10:08 AM 0 test
1 File(s) 0 bytes
2 Dir(s) 77,613,654,016 bytes free
example:
例子:
##代码##