Jump to content

Problem executing bash script using shell_exec


qteks200

Recommended Posts

Hi there,

I created a bash script file using following code to convert doc documents to pdf using OpenOffice macros.

 

*************************

doc2pdf:

#!/bin/sh

 

echo "hi"

DIR=$(pwd)

/usr/bin/oowriter "macro:///Standard.Word2PDF.DOC2PDF($1,$2)"

echo "bye"

***************************

 

when i execute doc2pdf /blah/blah.doc /blah/blah.pdf command from gnome-terminal it works fine.

 

But when i use following php script it just echo "hi" and "bye" but it doesn't execute the middle line.

***************************

<?php

print_r(shell_exec("doc2pdf args blah blah"));

?>

***************************

Please help me to find a solution.

 

Bests,

Link to comment
Share on other sites

Thx thorpe,

 

No it's not in the same directory as my php script. But i don't think this is point. As i mentioned, only middle line (this line `/usr/bin/oowriter "macro:///Standard.Word2PDF.DOC2PDF($1,$2)"`) is not executing. Also i tried shell_exec ('/usr/bin/oowriter "macro:///Standard.Word2PDF.DOC2PDF($1,$2)"'); but the problem still remains.

 

Link to comment
Share on other sites

  • 4 weeks later...

Hello,

 

I am new to php and i have a similar issue with shell_exec cmd

 

here is my php scripts:

 

testphp.php:

 

<html>
<head>


  
  <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">

  
  <title>testphp</title>
</head>


<body>


<table style="text-align: left; width: 574px; height: 60px;" border="0" cellpadding="2" cellspacing="2">


  <tbody>


    <tr>


      <td></td>


      <td>
      
      <form method="post">
Entrer le numero du user: <input name="user" type="text">  <input type="submit">
      </form>

<?php $myFile = "testFile.txt"; ?>
<?php $fh = fopen($myFile, 'w') or die("can't open file"); ?>
<?php $stringData = $_POST['user']; ?>
<?php fwrite($fh, $stringData); ?>
<?php fclose($fh); ?>
      </td>


    </tr>


    <tr>


      <td></td>
      <td>

      <a href="connect.php">connecter</a></td>
      <td></td>


    </tr>


  
  </tbody>
</table>


<br>


</body>
</html>

 

connect.php

<html>
<head>

  <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
  <title>connect</title>


</head>
<body>
<?php shell_exec('./connect3.sh');?>
<?php echo "patienter 1 minute";?>
</body>
</html>

 

connect3.sh

#!/bin/sh
read USR < /home/rom24x/www/testFile.txt
rm -rf /home/rom24x/www/flag/user$USR
echo 2 > /home/rom24x/www/flag/user$USR

 

The variable is passed from the phpscript to the sh script and echoing sh $USR variable to connect.php also works...

 

If i launch the connect.sh script (same user as server install ) in a terminal, the script works just fine... When launched from PHP script, variables are passed to sh script, sh script echo just fine in PHP but these lines are not:

 

rm -rf /home/rom24x/www/flag/user$USR

echo 2 > /home/rom24x/www/flag/user$USR

 

I have setted register_globals to On...

 

Can someone please help me making this work ?!?

 

Thank you  :)

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.