Reputation: 11
When running the following code, the nam file fails to open when the finish procedure is called. Here is my code:
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
I get this error
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"
I can however open the file directly from the nam GUI, What could be causing this problem?
Upvotes: 0
Views: 5815
Reputation: 137587
I'm assuming we're not dealing with something prosaic like a cd
between when you started writing that file and when you finished off? While Tcl can cd
, I really recommend that you don't.
Generally speaking, merely having a file in the current directory is not enough to make it executable; the OS also has to know to look in the current directory for executables (it's one of the places that Windows looks by default, and it's entirely configurable on all Unix variants) and the OS has to recognise that the file is executable at all.
For merely wanting to open the file in a viewer of some kind, you do not want to execute it! Instead, you want to open it. The way you do this varies by platform.
exec xdg-open [file normalize homework.nam] &
(Or gnome-open
or kde-open
.)
exec open [file normalize homework.nam] &
exec {*}[auto_execok start] "" [file nativename [file normalize homework.nam]] &
In all three cases, you might be able to skip the file normalize
; I'm just using that to get the fully-qualified name. The file nativename
flips the slashes around if necessary (and could be safely used on all three platforms). Windows requires the extra ""
because the START
shell builtin is pretty weird otherwise (which sucks but there you go).
I have absolutely no idea why Linux systems didn't call that program open
. Some things are inexplicable.
Upvotes: 1