theface Posted October 6, 2010 Share Posted October 6, 2010 When i try to do a shell_exec from my script the script does not work. But when i put the same thing in a .bat file and execute that from PHP it wroks. Can anyone help me shell_exec('xcopy C:\xampp\htdocs\test\backup\test.zip "\\fileserver\KT_backup\aback\" /i') Quote Link to comment Share on other sites More sharing options...
jammesz Posted October 6, 2010 Share Posted October 6, 2010 As i haven't used any windows past xp and i dont know which version you have i cant really help. I personally use linux and for me shell_exec needs a bit more info to work. Example: shell_exec("DISPLAY=:0 sudo -u username firefox ".$url); Now i know this will not work for you as your on windows but you should research the function a bit more and try and get some insight into what the function may need/require in order for it to work. On the other hand maybe on windows you don't need to do anything and it's just the command itself thats the problem. Quote Link to comment Share on other sites More sharing options...
theface Posted October 6, 2010 Author Share Posted October 6, 2010 I am using Windows Vista. when i do shell_exec('dir > dir.txt'); it works and creates a text file with the dir output. Probably its the syntax problem. Quote Link to comment Share on other sites More sharing options...
jammesz Posted October 6, 2010 Share Posted October 6, 2010 In that case, yes, i think its the command and not the function thats not working. Quote Link to comment Share on other sites More sharing options...
theface Posted October 6, 2010 Author Share Posted October 6, 2010 as i said before the command is ok when i run it from a bat file Quote Link to comment Share on other sites More sharing options...
jammesz Posted October 6, 2010 Share Posted October 6, 2010 what i really meant was, as you said before, that its probably a syntax error in the command. Quote Link to comment Share on other sites More sharing options...
phpchamps Posted October 6, 2010 Share Posted October 6, 2010 i am not sure whether this can help or not: but your problem seems to be similar (command working from batch file or command line and not through shell_exec). I found out that in my case some things needed to be set (which normally are set by default). the options -jo -j means: don't recreate the paths found in the archive -o means: always overwrite files And I needed to specify the destination path (even though it should unzip in the same directory when not specified), this is done by -d [path] The strange thing was that I didn't have to put these options when I would give the command on the command-line, only when I would call it with shell_exec. So the complete command in php would be for me: shell_exec('unzip -jo /path_to_archive/archive.zip -d /destination_path') And putting en echo in front will help you a lot. it should tell you something like this: Archive: /path_to_zip/archive.zip inflating: /destination_path/file1.jpeg inflating: /destination_path/file2.jpeg inflating: /destination_path/file3.jpeg 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.