kranthi117 Posted March 24, 2008 Share Posted March 24, 2008 when i test var_dump(is_callable("exec")); i m getting bool(true) but exec("whoami"); is not giving ny output (in fact ny command with exec is not giving ny output) can ny 1 tell me what it means??? Link to comment https://forums.phpfreaks.com/topic/97619-help-with-exec/ Share on other sites More sharing options...
cooldude832 Posted March 24, 2008 Share Posted March 24, 2008 where are u getting this exec function whoami??? Link to comment https://forums.phpfreaks.com/topic/97619-help-with-exec/#findComment-499456 Share on other sites More sharing options...
kranthi117 Posted March 24, 2008 Author Share Posted March 24, 2008 http://in.php.net/manual/en/function.exec.php Link to comment https://forums.phpfreaks.com/topic/97619-help-with-exec/#findComment-499457 Share on other sites More sharing options...
cooldude832 Posted March 24, 2008 Share Posted March 24, 2008 well is your server running unix or windows? Link to comment https://forums.phpfreaks.com/topic/97619-help-with-exec/#findComment-499461 Share on other sites More sharing options...
kranthi117 Posted March 24, 2008 Author Share Posted March 24, 2008 srry not telling that earlier Apache/2.2.8 (Win32) DAV/2 mod_ssl/2.2.8 OpenSSL/0.9.8g mod_autoindex_color Link to comment https://forums.phpfreaks.com/topic/97619-help-with-exec/#findComment-499471 Share on other sites More sharing options...
cooldude832 Posted March 24, 2008 Share Posted March 24, 2008 and whoami is a win32 shell command? oh wait win32 uses cmd not shell therefore exec of UNIX commands fail Link to comment https://forums.phpfreaks.com/topic/97619-help-with-exec/#findComment-499473 Share on other sites More sharing options...
kranthi117 Posted March 24, 2008 Author Share Posted March 24, 2008 ohh just overlook that ny alternative to run commands from php script in win??? Link to comment https://forums.phpfreaks.com/topic/97619-help-with-exec/#findComment-499477 Share on other sites More sharing options...
cooldude832 Posted March 24, 2008 Share Posted March 24, 2008 look around for answers of exec( ) on a win server cause I have never used a windows php server in my life Link to comment https://forums.phpfreaks.com/topic/97619-help-with-exec/#findComment-499482 Share on other sites More sharing options...
trq Posted March 24, 2008 Share Posted March 24, 2008 exec works fine on windows however the whoami command does not exist (on windows). Link to comment https://forums.phpfreaks.com/topic/97619-help-with-exec/#findComment-499490 Share on other sites More sharing options...
kranthi117 Posted March 24, 2008 Author Share Posted March 24, 2008 well i m testing <?php exec("test.exe"); var_dump(is_callable("exec")); ?> i m getting nothing more than bool(true) but typing test.exe in the command prompt is executing the file.. can sum 1 tell me where i m making a mistake Link to comment https://forums.phpfreaks.com/topic/97619-help-with-exec/#findComment-499538 Share on other sites More sharing options...
trq Posted March 24, 2008 Share Posted March 24, 2008 Exec doesn't output anything unless you specify an output variable as a second argument if thats what your getting at. Take a look at the manual. Link to comment https://forums.phpfreaks.com/topic/97619-help-with-exec/#findComment-499557 Share on other sites More sharing options...
cooldude832 Posted March 24, 2008 Share Posted March 24, 2008 the way i've learned to use exec on windows is to write it to a file and then fopen that file Link to comment https://forums.phpfreaks.com/topic/97619-help-with-exec/#findComment-499590 Share on other sites More sharing options...
kranthi117 Posted March 24, 2008 Author Share Posted March 24, 2008 @thorpe if this is what u r saying <?php exec("dir",&$out,$no); var_dump($out); var_dump($no); ?> i tried it but it did not work.... ny ways i m not trying to get a text output.. i m trying to start an exe file tru php.. @cooldude832 dnt get u how can i write the output of exec to a file, without using a php variable Link to comment https://forums.phpfreaks.com/topic/97619-help-with-exec/#findComment-499611 Share on other sites More sharing options...
rhodesa Posted March 24, 2008 Share Posted March 24, 2008 You don't need to write to a file to use it on Windows. If you just want the output to go to the screen, use passthru() If you want to store it in a variable, you will use exec() like so: $cmd = 'hostname'; $output = array(); $return_var = null; exec($cmd,$output, $return_var); print "Command run: $cmd\n"; print "Return Value: $return_var\n"; print "Output:\n".implode("\n",$output); Link to comment https://forums.phpfreaks.com/topic/97619-help-with-exec/#findComment-499626 Share on other sites More sharing options...
kranthi117 Posted March 24, 2008 Author Share Posted March 24, 2008 the above is giving results.. but only for text outputs... and as far as i hav read in php manual passthru does not support win, i m not trying to get an text output i m trying to start an .exe program tru php Link to comment https://forums.phpfreaks.com/topic/97619-help-with-exec/#findComment-499667 Share on other sites More sharing options...
rhodesa Posted March 24, 2008 Share Posted March 24, 2008 passthru() works fine on Windows (just tested with Windows/Apache/PHP5) what do you mean by "only text outputs"? what is an example of something else? Link to comment https://forums.phpfreaks.com/topic/97619-help-with-exec/#findComment-499674 Share on other sites More sharing options...
kranthi117 Posted March 24, 2008 Author Share Posted March 24, 2008 <?php $cmd = "\"\"C:\\windows\\system32\\notepad.exe\" \"C:\\test.txt\"\""; exec($cmd); ?> i expect this to open the win application "notepad.exe" and load "test.txt" into it... Link to comment https://forums.phpfreaks.com/topic/97619-help-with-exec/#findComment-499838 Share on other sites More sharing options...
rhodesa Posted March 24, 2008 Share Posted March 24, 2008 Ah, yes. You do not get an interactive commend shell. Link to comment https://forums.phpfreaks.com/topic/97619-help-with-exec/#findComment-499875 Share on other sites More sharing options...
kranthi117 Posted March 25, 2008 Author Share Posted March 25, 2008 ny work around for this??? Link to comment https://forums.phpfreaks.com/topic/97619-help-with-exec/#findComment-500153 Share on other sites More sharing options...
rhodesa Posted March 25, 2008 Share Posted March 25, 2008 I've never used proc_open before, but check out this post: http://us.php.net/manual/en/function.proc-open.php#70429 Link to comment https://forums.phpfreaks.com/topic/97619-help-with-exec/#findComment-500231 Share on other sites More sharing options...
kranthi117 Posted March 25, 2008 Author Share Posted March 25, 2008 tried that but without use Link to comment https://forums.phpfreaks.com/topic/97619-help-with-exec/#findComment-500235 Share on other sites More sharing options...
ansarka Posted March 25, 2008 Share Posted March 25, 2008 i dont think you can open applications using php command line execution you can communicate to application using commands not sure you can open notepad or any other application plz reply if i am wrong Link to comment https://forums.phpfreaks.com/topic/97619-help-with-exec/#findComment-500238 Share on other sites More sharing options...
cooldude832 Posted March 25, 2008 Share Posted March 25, 2008 i dont think you can open applications using php command line execution you can communicate to application using commands not sure you can open notepad or any other application please reply if i am wrong You are wrong. exec() is a function in php capable of executing an external program be it shell cmd or an ambiguous macro program made by a user. It is very common for MMORPG people to build macro's that "harvest" game resources and then report back to a remote server their findings via a php/cron/exec combo. Link to comment https://forums.phpfreaks.com/topic/97619-help-with-exec/#findComment-500518 Share on other sites More sharing options...
kranthi117 Posted March 26, 2008 Author Share Posted March 26, 2008 well is there ny way to call an external program (for e.g notepad.exe) from a php script?? as told earlier i m working on windows Link to comment https://forums.phpfreaks.com/topic/97619-help-with-exec/#findComment-501399 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.