Jump to content

Php exec() command


strawberry12

Recommended Posts

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 /c

I 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.

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 by strawberry12
Link to comment
Share on other sites

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... :-(

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.