wepnop Posted February 24, 2011 Share Posted February 24, 2011 Im creating a function for executing a system command. The idea is to show the command return. I use pre to show it, so i created a general function iPre that echos a string with that tag. The problem is that this code dont work. function compComando($com) { return escapeshellcmd($com); } function ejecComando($com) { $return = passthru(compComando($com)); if ($return) { return $return; } else { pe(); } } function iPre($txt) { echo '<pre>'; echo $txt; echo '</pre>'; } iPre(ejecComando('dir C:')); But if i call this simple code it works. Why? echo '<pre>'; echo ejecComando('dir C:'); echo '</pre>'; Here its shown well formatted, in the other no. I suppose thats something relating passing the string to the function...? Quote Link to comment Share on other sites More sharing options...
samoht Posted February 24, 2011 Share Posted February 24, 2011 are your sure ejecComando('dir C:') returns a string? Quote Link to comment Share on other sites More sharing options...
wepnop Posted February 24, 2011 Author Share Posted February 24, 2011 are your sure ejecComando('dir C:') returns a string? Yes. passthru returns the full command output if it goes well. And its returned and no error pe() raised. I tried using casting (string) to force it and it still didnt work. Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted February 24, 2011 Share Posted February 24, 2011 passthru() does not return anything. Check the manual. You will need exec() with the output arg or use back ticks `. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.