运行以下代码时,调用完成过程时nam文件无法打开。这是我的代码:
set ns [new Simulator]
#turn on multicast (for udp)
ns multicast
#turn on tracing
set nf [open homework.tr w]
$ns trace-all $nf
# turn on name
set namfile [open homework.nam w]
$ns namtrace-all $namfile
# Define finish procedure
proc finish {} {
global ns nf namfile
$ns flush-trace
close $namfile
close $nf
puts "running num..."
exec homework.nam &
exit 0
}
# Create 11 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
set n6 [$ns node]
set n7 [$ns node]
set n8 [$ns node]
set n9 [$ns node]
set n10 [$ns node]
# create 10 links
$ns duplex-link $n0 $n3 10Mb 10ms DropTail
$ns duplex-link $n1 $n3 10Mb 10ms DropTail
$ns duplex-link $n2 $n3 10Mb 10ms DropTail
$ns duplex-link $n3 $n4 1.5Mb 20ms RED
$ns duplex-link $n4 $n5 10Mb 10ms DropTail
$ns duplex-link $n4 $n6 10Mb 10ms DropTail
$ns duplex-link $n5 $n7 10Mb 10ms DropTail
$ns duplex-link $n5 $n8 10Mb 10ms DropTail
$ns duplex-link $n6 $n9 10Mb 10ms DropTail
$ns duplex-link $n6 $n10 10Mb 10ms DropTail
# set buffer size for $n3 $n4 link
$ns set queue-limit $n3 $n4 5
#set link orientation for nam
$ns duplex-link-op $n0 $n3 orient right-down
$ns duplex-link-op $n1 $n3 orient right
$ns duplex-link-op $n2 $n3 orient right-up
$ns duplex-link-op $n3 $n4 orient right
$ns duplex-link-op $n4 $n5 orient right-up
$ns duplex-link-op $n4 $n6 orient right-down
$ns duplex-link-op $n5 $n7 orient right-up
$ns duplex-link-op $n5 $n8 orient right
$ns duplex-link-op $n6 $n9 orient right
$ns duplex-link-op $n6 $n10 orient right-down
#set TCP connection
set tcp [new Agent/TCP]
set sink [new Agent/TCPSink]
$ns attach-agent $n9 $tcp
$ns attach-agent $n1 $sink
$ns connect $tcp $sink
#Setup a FTP over TCP connection
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
#Schedule events for FTP agent
$ns at 0.2 "$ftp start"
#allocate group addresses
set group [Node allocaddr]
#configure multicast protocol
set mproto DM
#nodes containing multicast protocol agents
set mrthandle [$ns mrtproto $mproto]
#Setup a UDP connection
set udp [new Agent/UDP]
$ns attach-agent $n7 $udp
$udp set dest_addr_ $group
$udp set dest_port_ 0
#Setup a CBR over UDP connection
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
#receiver agents
set rcvr [new Agent/LossMonitor]
#receiver agents joining the group
$ns at 0.0 "$n0 join-group $rcvr $group"
$ns at 0.0 "$n2 join-group $rcvr $group"
# start cbr at 0.2
$ns at 0.2 "$cbr start"
$ns at 1.5 "finish"
$ns run
我收到此错误
warning: using backward compatibility mode
running num...
ns: finish: couldn't execute "homework.nam": no such file or directory
while executing
"exec homework.nam &"
(procedure "finish" line 8)
invoked from within
"finish"
但是我可以直接从nam GUI打开文件,可能是什么导致了这个问题?
答案 0 :(得分:1)
我假设在您开始编写该文件和完成文件之间我们并未处理像cd
这样平淡无奇的事情?虽然Tcl 可以 cd
,但我真的建议您不要。
一般来说,仅在当前目录中有一个文件不足以使其可执行;操作系统还必须知道在当前目录中查找可执行文件(它是Windows默认查找的地方之一,并且它可以在所有Unix变体上完全配置)并且操作系统必须识别该文件完全可以执行。
仅仅想要在某种查看器中打开文件,不想要执行它!相反,您想要打开它。你这样做的方式因平台而异。
exec xdg-open [file normalize homework.nam] &
(或gnome-open
或kde-open
。)
exec open [file normalize homework.nam] &
exec {*}[auto_execok start] "" [file nativename [file normalize homework.nam]] &
在所有三种情况下,您可能能够跳过file normalize
;我只是用它来获得完全限定的名字。如果需要,file nativename
会翻转斜杠(并且可以安全地在所有三个平台上使用)。 Windows需要额外的""
,因为内置的START
shell非常奇怪(这很糟糕但你去了)。
我完全不知道为什么Linux系统没有调用该程序open
。有些事情是莫名其妙的。