Jump to content

Archived

This topic is now archived and is closed to further replies.

Branden Wagner

system command

Recommended Posts

$pass = system("mail/crypt $password");

works and does the crypt right however it also prints it on the screen and i dont want it to output the crypt on to the screen what am i doing wrong?

Share this post


Link to post
Share on other sites
You can redirect the ouput to a file or another voutput stream (such as a null device).

[code]$pass = system("mail/crypt $password >file.txt");[/code]

Share this post


Link to post
Share on other sites
[code]$pass = exec("mail/crypt $password");[/code]

Try that, I believe that [url=http://php.net/exec]exec[/url] do not output the result.

Share this post


Link to post
Share on other sites
You can use the trick from the PHP manual comments. This one works, capturing all exec output in an array that you can walk.
[code]<?php
$result = array();
exec( "dir", &$result);
foreach ( $result as $v )
{
echo "HEREITIS: $v <br />";
}
?>[/code]

Share this post


Link to post
Share on other sites
I really don't know the nitty gritty of the differences between these 2 commands, but I always use exec because it returns my output nicely in an array. The following shows the definitions from tht PHP documentation:
[code]string system ( string command [, int return_var])

system() is just like the C version of the function in that it executes the given command and outputs
the result. If a variable is provided as the second argument, then the return status code of the executed
command will be written to this variable.

[/code]
[code]string exec ( string command [, array output [, int return_var]])

exec() executes the given command, however it does not output anything. It simply returns the last line
from the result of the command. If you need to execute a command and have all the data from the
command passed directly back without any interference, use the passthru() function. If the output
argument is present, then the specified array will be filled with every line of output from the command.

[/code]

Share this post


Link to post
Share on other sites
[quote author=ronverdonk link=topic=103143.msg411716#msg411716 date=1155043827]
I really don't know the nitty gritty of the differences between these 2 commands
[/quote]

If you read the quotes you posted, then you would know that system outputs the result and exec returns the last line of the result.

Share this post


Link to post
Share on other sites
Are you earning brownie points for this post? I was talking about the internals (nitty gritty) of both commands, not about the externals such as returning output or not.

Share this post


Link to post
Share on other sites
Well, there is no difference in how the command is executed, the only difference is the output/returning.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.