Jump to content


Photo

system command


  • Please log in to reply
9 replies to this topic

#1 Branden Wagner

Branden Wagner
  • Members
  • PipPipPip
  • Advanced Member
  • 111 posts

Posted 06 August 2006 - 04:55 AM

$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?

#2 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 06 August 2006 - 10:04 AM

You can redirect the ouput to a file or another voutput stream (such as a null device).

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

RTFM is an almost extinct art form, it should be subsidized.

#3 Branden Wagner

Branden Wagner
  • Members
  • PipPipPip
  • Advanced Member
  • 111 posts

Posted 07 August 2006 - 12:42 PM

i just want the output stored in the $pass variable. because the next step in the script it to put it in the db.

#4 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 07 August 2006 - 01:39 PM

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

Try that, I believe that exec do not output the result.

#5 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 07 August 2006 - 02:21 PM

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

RTFM is an almost extinct art form, it should be subsidized.

#6 Branden Wagner

Branden Wagner
  • Members
  • PipPipPip
  • Advanced Member
  • 111 posts

Posted 07 August 2006 - 09:10 PM

exec worked thanks.... so... whats the difference between system and exec??

#7 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 08 August 2006 - 01:30 PM

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:
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. 

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. 


RTFM is an almost extinct art form, it should be subsidized.

#8 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 08 August 2006 - 01:52 PM

I really don't know the nitty gritty of the differences between these 2 commands


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.

#9 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 08 August 2006 - 02:17 PM

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.
RTFM is an almost extinct art form, it should be subsidized.

#10 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 08 August 2006 - 05:31 PM

Well, there is no difference in how the command is executed, the only difference is the output/returning.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users