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...? Link to comment https://forums.phpfreaks.com/topic/228681-strange-format-error/ 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? Link to comment https://forums.phpfreaks.com/topic/228681-strange-format-error/#findComment-1179094 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. Link to comment https://forums.phpfreaks.com/topic/228681-strange-format-error/#findComment-1179122 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 `. Link to comment https://forums.phpfreaks.com/topic/228681-strange-format-error/#findComment-1179124 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.