jaimitoc30 Posted October 10, 2007 Share Posted October 10, 2007 Hi, everybody. I have a question. Currently I have this code: $cmd=exec("start c:\\windows\\system32\\cmd.exe"); to run a command line. I tried: $command=fwrite($cmd, "telnet x.x.x.x") to execute that command in the same window that opened, however it will not do so. How can I launch a shell and start sending commands to that shell that I opened. Currently shell_exec() and system() only allows me to run one command, however I need to run several commands in the same command line, not another one. It is like an interaction with the command line. I would appreciate any assistance with this. Quote Link to comment https://forums.phpfreaks.com/topic/72631-php-commands-execution/ Share on other sites More sharing options...
trq Posted October 10, 2007 Share Posted October 10, 2007 If you need to run several commands in one go seperate them with semi colons. eg; <?php exec('command one; command two; command three'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/72631-php-commands-execution/#findComment-366194 Share on other sites More sharing options...
jaimitoc30 Posted October 10, 2007 Author Share Posted October 10, 2007 GREAT!! Thank you so much, and what if I need an sleep() to wait for a shell response, for example if I do this: $cmd=exec("START c:\\windows\\system32\cmd.exe";"telnet x.x.x.x"); and I need to wait for all the stuff that it will send it to then add another thing like my login or password? I work for a cell phone company, and I need to make an automatization. I need to connect to a telnet server. I used SSH before, but the server admin closed port 22 and I tried to look PHP telnet help to interact with telnet however the classes that I found where no good and I tried to modify the classes without success, so I decided doing it in this way. Thxs in advance. Quote Link to comment https://forums.phpfreaks.com/topic/72631-php-commands-execution/#findComment-366197 Share on other sites More sharing options...
jaimitoc30 Posted October 10, 2007 Author Share Posted October 10, 2007 Any assistance Quote Link to comment https://forums.phpfreaks.com/topic/72631-php-commands-execution/#findComment-366205 Share on other sites More sharing options...
trq Posted October 10, 2007 Share Posted October 10, 2007 There is no point in starting cmd.exe, you simply don't need it. Also, exec returns a string, the last line of text outputted by the command. Do you really need to save that? If the program your trying to interact with (ie telent) prompts for input, you will need to do this another way. Your on a windows box so I'm afraid I can't be of much more assistance. PS: I edited your last post. If you want someone to do this for you we have a freelance board. Quote Link to comment https://forums.phpfreaks.com/topic/72631-php-commands-execution/#findComment-366207 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.