Jump to content

Unbale to use shell_exec


theface

Recommended Posts

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')  

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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.