0

I'm using shell_exec in PHP which works if I use the executable in the same folder, but doesn't work anymore if I point executable in subfolder.

I have this (which works):

shell_exec ("makescreen.exe /url=".$link."");

I would like to have this (doesn't work - it just skips the execution):

shell_exec ("/screens/makescreen.exe /url=".$link."");

Oh, and paths are in Windows mode.

Thanks for your help guys.

2 Answers 2

3

try using exec () with the complete path rather than relative path

 $oldcwd = getcwd();
 chdir($oldcwd+"/screens");
 exec("makescreen.exe /url=".$link."");
  chdir($oldcwd); 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, but still the same thing. This is 2 levels deep from server root already, and now I would like another subfolder - is this has to do anything with it? Should I be using absolute path from server root?
1

Be care of the difference of absolute path. relative path. execute path. For example, your dir structure is:

/home/my/php/script/test.php 
                   /makescreen.exe

and in you php script you call shell_exec(makescreen.exe ***).

In this case, if you execute your script like cd /home/my/php/script && php test.php, then the execute path is /home/my/php/script/ and the scirpt will find makescreen.exe in execute path, here is /home/my/php/script/

However, if you currently stay in /home/my and use this way php /home/my/php/script/test.php then the execute path is your current path, here is /home/my, and the script will find the makescreen.exe in /home/my, definitely failed.

If you use /home/my/php/script/makescreen.exe in your script, this is absolute path and wherever you are, it will find makescreen.exe in /home/my/php/script/

And if you want to put the executable file in subfolder. you can use relative path subfolder/makescreen.exe in your script and make sure the script can access it correctly.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.