【问题标题】:Running DOS command or batch file in tcl script in Windows 7 with ActiveTcl 8.5在 Windows 7 中使用 ActiveTcl 8.5 在 tcl 脚本中运行 DOS 命令或批处理文件
【发布时间】:2011-09-29 22:54:57
【问题描述】:

以下是tcl代码

#!/bin/sh
# \
exec tclsh "$0"  ${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

我收到以下消息:

无法执行“C:\Windows\System32\cmd.exe \c dir”:没有这样的文件或目录 在执行时 “执行 [auto_execok 目录]” (文件“mytst.tcl”第 35 行)

但是 ping 工作正常。

【问题讨论】:

  • 那必须是/c。正斜杠,而不是反斜杠。祝你好运找到那个错误。好在它是开源的。

标签: windows exec dos tcl


【解决方案1】:

auto_execok 返回一个列表,该列表作为单个参数传递给exec。您需要展开列表:

exec {*}[auto_execok dir]

示例:

% 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

【讨论】:

  • 我会的,但我在触摸板上写字,无法访问 Win 框。
  • % exec {} [auto_execok dir] 无法执行“”:没有这样的文件或目录 - 如何检查 ActivestateTcl 是否安装正确?谢谢
  • @action,}[ 之间没有空格! Documentation is here
  • @glenn 谢谢。一个简单的 DOS 批处理文件:'cd c:\;目录;'在 tclsh 中,批处理文件运行成功。在 tcl 脚本中,'#!/bin/sh #\exec tclsh "$0" ${1+"$@"} set env(TERM)dumb exec {*}[auto_execok dir] exec mytst.bat return
  • ' c:\tclsh mytst.tcl could't execute "mytst.bat": no such file or directory while execution "exec mytst.bat" (file "mytst.tcl" line 6) Line 5 既没有执行,也没有显示在标准输出上。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-23
  • 1970-01-01
  • 2015-12-14
  • 2013-02-27
相关资源
最近更新 更多