Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Problem with exec() #76

Closed
daniel-arrick opened this issue Apr 20, 2020 · 9 comments
Closed

Problem with exec() #76

daniel-arrick opened this issue Apr 20, 2020 · 9 comments

Comments

@daniel-arrick
Copy link

I'm trying to run shell commands using exec/shell_exec but I get errors like:

/bin/ls: /bin/ls: cannot execute binary file

Some sort of environment configuration I am missing?

Thank you

@jakubmisek
Copy link
Collaborator

exec/shell_exec is somehow supported, but it may be not tested on Linux and macOs.

What environment and what shell command are you running?

@daniel-arrick
Copy link
Author

daniel-arrick commented Apr 21, 2020

I use MacOS for development and linux for deployment. At first I was trying to use aws cli commands but those failed due to problems with running python scripts from exec(). Then I tried something more rudimentary like "ls" and that failed so it seems like a more general issue with the environment.
Example response from "ls" command: /bin/ls: /bin/ls: cannot execute binary file

@jakubmisek
Copy link
Collaborator

quick question - how is this issue related to WordPress?

jakubmisek added a commit to peachpiecompiler/peachpie that referenced this issue Apr 24, 2020
@daniel-arrick
Copy link
Author

Do you mean what I am trying to accomplish?
What I am trying to accomplish is a way to manage my media content on AWS S3. I cannot find a plugin that is natively supported by the Peachpie compiler mostly due to yielding from try catch finally in the PHP AWS SDK is not supported I believe. That leads me to trying the command line interface and investigating how I can integrate it using hooks ands filters.

@jakubmisek
Copy link
Collaborator

oh so you are implementing your WordPress plugin?

AFAIK yielding from try catch is easy to workaround:

try
{
  yield $x;
}

->

try
{
  $value = $x;
}
yield $value

it just have to be done manually, compiler does not have this kind of analysis (yet).

@daniel-arrick
Copy link
Author

Ok thanks for the tip! I'll have to try that out.
I missed you added unix shell support in the comment above. Thank you again, I will test it out the new compiler soon

@daniel-arrick
Copy link
Author

daniel-arrick commented Apr 27, 2020

Thank you for releasing the new compiler with unix shell support.
After lots of trials I found that in order to execute a command with arguments I needed to surround the entire command with double quotes.

This works
shell_exec("ls");

This fails as the "-l" flag is excluded for some reason
shell_exec("ls -l");

This works
$cmd = "ls -l";
shell_exec("\"$cmd\"");

This works
shell_exec('"ls -l"');

@jakubmisek
Copy link
Collaborator

thanks daniel! great tips, this should be easy to fix for us

@jakubmisek
Copy link
Collaborator

should be fixed in the latest update :) please let me know if it still fails

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants