October 1, 2010

Using Shell code in Perl - `Backticks`

HI all. First time poster here, so please bear with me.

I have a real time data feed that I'm pulling data off of into a local port. The command I use to grab the data is
"netcat localhost 12345".
This command works perfectly in the shell command line. The problem is that it runs continuously. To have it run only for 100 ms would be perfect.
In the Perl Script I am implementing this command with, my goal is to put each line into a string so I can parse the data, filter if need be, and do it again as a loop. The following commands are in a while(1) loop. I tried a number of things to get the data into a string line by line...

while(`netcat localhost 12345`) #because I know that backticked system commands return their output to the STDOUT

while(!`netcat localhost 12345`) #I thought maybe it worked with negative logic

$new_line = `netcat localhost 12345`; #This just didnt work at all...

`echo |netcat localhost 12345 >> $new_line`;

Unfortunately none have worked. I know that you can netcat the data into a file, but I would like to like to cut out the middle man, if possible. Hopefully someone knows a simple command that can help me.

Click Here!