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
https://forums.phpfreaks.com/topic/277877-php-exec-command/
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
https://forums.phpfreaks.com/topic/277877-php-exec-command/#findComment-1429490
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?

Link to comment
https://forums.phpfreaks.com/topic/277877-php-exec-command/#findComment-1429520
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
https://forums.phpfreaks.com/topic/277877-php-exec-command/#findComment-1429537
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.