I’m trying to output a system netstat -an -p TCP $interval > $log for a sleep of $seconds, and then quit/kill the netstat command but am having trouble getting it to work correctly.
If I use start netstat..., my sleep and kill commands work, but it does not write to the log.
If I only use netstat..., then it writes to the logs, but will not move on to the sleep and kill commands.
Any ideas on how to solve this??
$netstat_cmd = "netstat -an -p TCP $interval >$netstatlog;
$stop_netstat_cmd = "c:\utilities\pskill NETSTAT.exe";
system($netstat_cmd);
sleep $seconds;
system "$stop_netstat_cmd";
Thanks!
Why don’t you use
IPC::Run? It has akill_kill()method that is portable across Unix and Win32 (the latter is important if you’re running on Windows as your “start” seems to possibly indicate).As far as your own approach, the
start xxxredirect doesn’t work, so the easiest fix is to:Create a batch file to run netstat and redirect to a file
Launch the batch file with
start