Karl Hilts - 2003-08-23

Folks,

The following is a trival code example of one program creating another, executing it, gatering it's output, and removing it.  It is written in Perl, of course.  And it works too.  Just food for thought.

Now it's off to the lake for an overnighter on the boat of a friend and a vist to a bar.  See I have a life too.

#! /usr/bin/perl -w

######################################################################
#
# a simple attempt to have one application build another
# executable application and execute it, capturing the
# results and diplaying them.
#
######################################################################

# code to be copied to a file
$my_code0 = "#! /usr/bin/perl\n\n";
$my_code1 = "print(\"Hello world\\n\");\n\n";
# create and open a file
open(SINK, "> test.pl");
# write to the file
print(SINK "$my_code0");
print(SINK "$my_code1");
# close the file
close(SINK);
# chmod 0755, making it executable
system("chmod 0755 ./test.pl");
# execute the file returning the results with back-ticks
$answer = `./test.pl`;
# delete the file
system("rm ./test.pl");
# print the results
print("\n\nThe answer is $answer\n");