0

I have an application which publishes realtime market data rates. This app is invoked from the command line and has an interactive mode where the user can change various parameters on-the-fly by simply typing the parameter followed by it's corresponding value.

e.g. ur 2000

would dynamically set the update rate to 2000 updates per second.

What I need to do is perform some soak testing for several hours/days and I need to be able to change the update rate to different values at random times. I normally do all my scripting using Perl so I need a way of invoking the script (easy enough) but then having the ability for the script to randomly change any given parameter (like the update rate).

Any ideas or advice would be really appreciated.

Thanks very much

Wilko
  • 289
  • 1
  • 4
  • 14

2 Answers2

1

You can open a pipe to your program with open my $fh, "|-", ... and then set the handle to autoflush with

select $fh;
$| = 1;

Now you have a direct line to the standard input of your system under test, as in the demonstration below.

#! /usr/bin/env perl

use strict;
use warnings;
no warnings "exec";

my @system_under_test = ("cat");

open my $fh, "|-", @system_under_test or die "$0: open @system_under_test: $!";

select $fh;
$| = 1;  # autoflush

for (map int rand 2000, 1 .. 10) {
  print $fh "ur $_\n";
  sleep int rand 10;
}

close $fh or warn "$0: close: $!";

For your soak test, you would of course want to sleep for more intervals and iterate the loop many more times.

Greg Bacon
  • 134,834
  • 32
  • 188
  • 245
  • Thank you very much for this Greg. It's exactly what I'm looking for and it has also taught me a few more little Perl tricks. – Wilko Mar 19 '13 at 14:10
  • I jumped the gun. I've used exactly what you put above but changed the for loop into a while() and obviously changed the @system_under_test to my App with all of it's other command line args. What I see happen is the Update Rate getting set on the first iteration of the loop. It then stays at that rate (even though it continues looping and setting new random values). On the screen, I see what I'd normally see if I ran from the command line although it's spamming the screen continually with the prompt outputted by the App (e.g. Enter Command (help):Enter Command (help):......etc etc – Wilko Mar 19 '13 at 15:15
  • I wonder if having the Args is affecting the open in some way? @system_under_test = ("./sink_driven_src -S TESTSRC1 -c -l 140 -N 8101 -E ssl45 -Q EBOND_LDN.out -b"); – Wilko Mar 19 '13 at 15:24
  • @Wilko Is the user supposed to press Enter to send a command? – Greg Bacon Mar 19 '13 at 16:09
  • Hi Greg, yes indeed. An Enter is required. Sorry I missed that off my original post – Wilko Mar 20 '13 at 07:21
  • I've now put a \n on the print $fh line and now it works perfectly. Many thanks again for your help Greg. – Wilko Mar 20 '13 at 07:36
0

You can use the command "mkfifo". This creates a named pipe. If you start your program using the fifo as input it should work.

Create a fifo:

mkfifo MyFifo

Start your application with fifo as input:

./yourAppName < MyFifo

Now all you write (e.g. using echo) to "MyFifo" will forwarded to yourAppName's stdin.

mstrewe
  • 441
  • 3
  • 15