https://www.nsnam.org/mediawiki/index.php?title=Exec&feed=atom&action=historyExec - Revision history2024-03-28T18:14:55ZRevision history for this page on the wikiMediaWiki 1.24.1https://www.nsnam.org/mediawiki/index.php?title=Exec&diff=1862&oldid=prevTomh: how to exec a script2008-09-05T04:27:47Z<p>how to exec a script</p>
<p><b>New page</b></p><div>This sample pertains to launching an external shell script from your ns-3 program.<br />
<br />
> > Can I run a batch file which extracts trace parameters from the main<br />
> > trace file for plotting purposes in NS3. I.e. can i add a line under<br />
> > the finish proc to run my trace.sh?<br />
> > <br />
> > proc finish {} {<br />
> > global ns<br />
> > $ns flush-trace<br />
> > *bash trace.sh*<br />
> > exec nam out.nam &<br />
> > exit 0<br />
> > }<br />
<br />
Yes, in C++ you can do this with execl(). You can read the man page on execl but here is a brief example usage:<br />
<br />
diff -r 5209cecd2ade samples/main-simulator.cc<br />
--- a/samples/main-simulator.cc Thu Sep 04 13:29:13 2008 -0700<br />
+++ b/samples/main-simulator.cc Thu Sep 04 21:17:50 2008 -0700<br />
@@ -2,6 +2,7 @@<br />
#include "ns3/simulator.h"<br />
#include "ns3/nstime.h"<br />
#include <iostream><br />
+#include <unistd.h><br />
<br />
using namespace ns3;<br />
<br />
@@ -43,5 +44,6 @@ int main (int argc, char *argv[])<br />
<br />
Simulator::Run ();<br />
+ execl("/bin/bash", "/home/user/ns-3-dev/trace.sh", "trace.sh", NULL);<br />
Simulator::Destroy ();<br />
}<br />
<br />
[[Category:Samples]]</div>Tomh