"
";
}
The Perl script is quite simple; no third-party modules are required, so you could test
this example with little time investment. If you??™re running Linux, chances are very
306 CHAPTER 10 ?– WORKING WITH THE FI LE AND OPERATING SYSTEM
good that you could run this example immediately because Perl is installed on every
respectable distribution. If you??™re running Windows, check out ActiveState??™s (http://
www.activestate.com/) ActivePerl distribution.
Like languages.pl, the PHP script shown here isn??™t exactly rocket science; it simply
calls the Perl script, specifying that the outcome be placed into an array named $results.
The contents of $results are then output to the browser:
$outcome = exec("languages.pl", $results);
foreach ($results as $result) echo $result;
?>
The results are as follows:
perl
php
python
java
c
Retrieving a System Command??™s Results
The system() function is useful when you want to output the executed command??™s
results. Its prototype follows:
string system(string command [, int return_var])
Rather than return output via an optional parameter, as is the case with exec(), the
output is returned directly to the caller. However, if you would like to review the execution
status of the called program, you need to designate a variable using the optional
parameter return_var.
For example, suppose you??™d like to list all files located within a specific directory:
$mymp3s = system("ls -1 /home/jason/mp3s/");
The following example calls the aforementioned languages.
Pages:
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381