[ Team LiB ] Previous Section Next Section

Workshop

Quiz

1:

Which function would you use to open a pipe to a process?

2:

How would you read data from a process after you have opened a connection?

3:

How can you write data to a process after you have opened a connection to it?

4:

Will the exec() function print the output of a shell command directly to the browser?

5:

What does the system() function do with the output from an external command it executes?

6:

What does the backtick operator return?

7:

How can you escape user input to make it a little safer before passing it to a shell command?

8:

How might you execute an external CGI script from within your script?


Answers

A1:

You open a connection to a process with the function popen().

A2:

You can read from a process you have opened with popen() as you would from a file. In other words, you can use functions such as feof() and fgets().

A3:

You can write to a process as you could with a file, usually with the fputs() function.

A4:

The exec() function accepts an array variable, which it fills with the output of the shell command it makes. Output is not sent directly to the browser.

A5:

The system() function prints the output of the external command directly to the browser.

A6:

The backtick operator returns the output of the external command it calls. This can be stored, parsed, or printed.

A7:

You can escape user input to make it safer using the escapeshellcmd() function. The safest way to execute shell commands, though, is to refrain from passing user input at all.

A8:

The virtual() function calls an external CGI script.


    [ Team LiB ] Previous Section Next Section