in reply to calling Unix commands

Max_Glink,

Coincidentally I just came across some code on a new project that speak to the issue of "what method to use to execute a unix command".

The code needed to get the output from an in-house employee lookup program and return some of the values to an HTML page.

The method being used was using "system" and piping the command output to a tempfile, then opening the tempfile and getting the data back out for display. Although functional, it was not especially efficient.

My alternative was to use "backticks" for the command, which allowed me to capture the output to an array, which I then passed to the parser than was managing the array created by the file read.

Here are the two methods.

# assume $lname, $tempfile were assigned previously my $command = "unix_blues -w $lname >> $tempfile"; my $rc = system($command); # the above puts the output into $tempfile and the return code in $rc # they then open, read the tempfile putting lines into array (which co +uld have # also been done in one line)

One problem with the above was that for whatever reason, they occasionally had tempfiles lying around from failed unlinks.

So I changed it to this, which resolved the tempfile issue and removed the file I/O

my $command = "unix_blues -w $lname"; @BluesData = `$command`;

the above put the output lines into @BluesData which I then passed to an existing routine that parsed it.

It sped things up considerably.

Just more proof TIMTOWTDI!

Good luck!