jhsachs Posted October 11, 2011 Share Posted October 11, 2011 I'm experimenting with the shell_exec function to gain shell capability on a Linux host that doesn't provide it otherwise. I've found that I can see what is in different directories by entering a command line like: cd ..; ls but if I enter two consecutive command lines: cd .. ls The cd command has no effect. Apparently shell_exec is using a new shell every time I call it. Is there a way to start a shell in a PHP script and keep it active while I pass it multiple commands, so that this won't happen? Quote Link to comment https://forums.phpfreaks.com/topic/248890-running-shell-commands/ Share on other sites More sharing options...
trq Posted October 11, 2011 Share Posted October 11, 2011 Not using php alone. You could write a simple Ajax based form that would post your commands to shell_exec one at a time though. Quote Link to comment https://forums.phpfreaks.com/topic/248890-running-shell-commands/#findComment-1278145 Share on other sites More sharing options...
WebStyles Posted October 11, 2011 Share Posted October 11, 2011 also, many commands can be done on one line... this: cd ..; ls is the same as: ls ../ Quote Link to comment https://forums.phpfreaks.com/topic/248890-running-shell-commands/#findComment-1278146 Share on other sites More sharing options...
trq Posted October 11, 2011 Share Posted October 11, 2011 this: cd ..; ls is the same as: ls ../ No it's not. It might look similar, but it has two completely different effects. It's is true though that you can separate commands via ; Quote Link to comment https://forums.phpfreaks.com/topic/248890-running-shell-commands/#findComment-1278159 Share on other sites More sharing options...
WebStyles Posted October 11, 2011 Share Posted October 11, 2011 The list of files will be the same (in this particular example), except it won't move you into the directory... still, since it's a simple php script that's always running from the same directory, always including the path to execute the commands could help. Anyway, a simple google search for 'php shell terminal' returned this: http://sourceforge.net/projects/phpterm/. hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/248890-running-shell-commands/#findComment-1278169 Share on other sites More sharing options...
jhsachs Posted October 11, 2011 Author Share Posted October 11, 2011 The SourceForge listing looks promising. I'll look into it. How would the Ajax solution work? I thought Ajax just provided a channel for the client to communicate with a server script between page loads. The script to do anything that it couldn't do without Ajax in the picture. Quote Link to comment https://forums.phpfreaks.com/topic/248890-running-shell-commands/#findComment-1278249 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.