Exec
Jump to navigation
Jump to search
This sample pertains to launching an external shell script from your ns-3 program.
> > Can I run a batch file which extracts trace parameters from the main
> > trace file for plotting purposes in NS3. I.e. can i add a line under
> > the finish proc to run my trace.sh?
> >
> > proc finish {} {
> > global ns
> > $ns flush-trace
> > *bash trace.sh*
> > exec nam out.nam &
> > exit 0
> > }
Yes, in C++ you can do this with execl(). You can read the man page on execl but here is a brief example usage:
diff -r 5209cecd2ade samples/main-simulator.cc
--- a/samples/main-simulator.cc Thu Sep 04 13:29:13 2008 -0700
+++ b/samples/main-simulator.cc Thu Sep 04 21:17:50 2008 -0700
@@ -2,6 +2,7 @@
#include "ns3/simulator.h"
#include "ns3/nstime.h"
#include <iostream>
+#include <unistd.h>
using namespace ns3;
@@ -43,5 +44,6 @@ int main (int argc, char *argv[])
Simulator::Run ();
+ execl("/bin/bash", "/home/user/ns-3-dev/trace.sh", "trace.sh", NULL);
Simulator::Destroy ();
}