exec() does not execute the past command

Asked

Viewed 504 times

1

I’m trying to use the function exec() from PHP to run a file. jar (I know it’s not good practice, but it’s the only solution I have at the moment), but I’m not getting good results.

The code in question:

exec(java -jar /home/sistemas/relatorios/jasper_reports/NaturatinsJasperReports/NaturatinsJasperReports.jar 'SELECT * FROM ambiental.vw_fin_fua_ato_azul WHERE id_fua = 31968408 ' '/home/sistemas/relatorios/jasper_reports/jasper/memoria_calculo_azul.jasper' '/home/sistemas/relatorios/memoria_calculo_azul.pdf' '/home/sistemas/relatorios/jasper_reports/NaturatinsJasperReports/desenvolvimento.xml', $output)

Run and simply get empty return. The variable $output comes set with a Array and nothing else. However, the command passed by parameter works perfectly when executed via terminal.

Does anyone have any idea about?

Thank you.

  • No, none. I’ve even switched the path characters to just tiny, but nothing so far.

  • Are not missing the "" ?

  • In reality, a string type variable is passed between "".

  • what php log says?

  • 1

    Great idea, @Brunorozendo. Unrecognized option: -jar
Could not create the Java virtual machine.
: not founde/sistemas/relatorios/jasper_reports/naturatins_jasper_reports/naturatins_jasper_reports.jar
: not foundCT * FROM ambiental.vw_fin_fua_ato_azul WHERE id_fua = 31968408 
: not founde/sistemas/relatorios/jasper_reports/jasper/memoria_calculo_azul.jasper
: not founde/sistemas/relatorios/memoria_calculo_azul.pdf
sh: 6: /home/sistemas/relatorios/jasper_reports/naturatins_jasper_reports/desenvolvimento.xml: Permission denied. I’m trying to solve.

  • Solved! The first problem was the permission of the XML file I pass as parameter, the second was that I broke the command on different lines to make it easier to read. Just change the XML permissions and merge the entire command into a single line. Thank you all.

Show 1 more comment

1 answer

1

It may be the permission of the User, basically you are running the web server with an X user, so you can only run programs and functions where the X user has permissions due.

Try changing the file permissions or the user the server uses.

  • Just in case, I gave 777 all the way. Initially, there was a file actually refusing access, now the message I get is Unable to access jarfile, but the way is right.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.