strawberry12 Posted May 10, 2013 Share Posted May 10, 2013 I have a shell command in Windows that copies and renames a folder to the same location. The working command looks like this: xcopy \\my-server\ourstuff\live_projects\xxxx_Project\*.* \\my-server\ourstuff\live_projects\projectstr /e /k /i /cI want to execute this command from within PHP using the exec() function. projectstr should really be a string variable ($projectstr) that, at present, may contain alphanumeric characters, spaces, minus signs, and underscores, but not commas, apostophes, or quotation marks. Is there a simple technique for rewriting this for the exec() command? I get so lost in backslashes and quotation marks that I don't know whether I'm coming or going. Any help appreciated. Quote Link to comment Share on other sites More sharing options...
gristoi Posted May 10, 2013 Share Posted May 10, 2013 php comes with some helpful constants and methods that can help. the one you will be concerned with is : DIRECTORY_SEPERATOR // an example would be $fileDir = 'dir1'.DIRECTORY_SEPERATOR.'dir2'.DIRECTORY_SEPERATOR.......... and so on so the above would give you dir1/dir2/..... on a linux machine, and is clever enough to translate it to dir1\dir2 on windows Quote Link to comment Share on other sites More sharing options...
strawberry12 Posted May 10, 2013 Author Share Posted May 10, 2013 (edited) Thanks, I didn't know about that constant. However, I don't think that's quite the problem... My code currently looks like this... $string = "xcopy \\\\my-server\\ourstuff\\live_projects\\xxxx_Project\\*.* \\\\my-server\\ourstuff\\live_projects\\$projectstr /e /k /i /c"; echo $string; exec($string); Given a $projectstr like '9999_test', the echo looks like this: xcopy \\my-server\ourstuff\live_projects\xxxx_Project\*.* \\my-server\ourstuff\live_projects\9999_test /e /k /i /c The exec doesn't do anything, but if I cut and paste that echo into the command line, it works fine - so what am I missing? Edited May 10, 2013 by strawberry12 Quote Link to comment Share on other sites More sharing options...
strawberry12 Posted May 10, 2013 Author Share Posted May 10, 2013 OK, I've been playing about some more, and it now seems that this is really a permissions issue. My guess is that our IT people performed some kind of server update that has had the effect of restricting apache's/php's permissions in some way. So a different kind of problem altogether... :-( 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.