Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2004
    Posts
    1

    Unanswered: PHP error running Shell Script

    I have made a file TestCopy.php to try and execute a shell script!
    <?php
    echo "Hello just to check that I am Here";
    exec ("tst.sh test.txt test1.txt");
    echo "<br> That was it I wonder what the result is?";
    ?>

    tst.sh is as follows:
    cat $1 > $2
    echo "** Transalation succesful ** " >> $2

    I mark my directory as CHMOD 777.
    I have marked TestCopy.php as CHMOD 777
    I have marked tst.sh as CHMD 777.
    I try to execute the script

    http://www.manorhouses.com/OTHER-WEB...d/TestCopy.php

    It seems to execute, I can see my echo's being displayed,
    I receieve no error message. But after execution no output file!!!!
    Can anyone please help??

    I am basically trying to pass a file to an executable “tst.sh”, read a file then write the results back to a new file?

  2. #2
    Join Date
    Nov 2006
    Location
    Australia
    Posts
    3
    After copying your code (almost, I added end of lines characters "\n" to the end of the echo statements and removed the <br>) and set the permissions (a little bit stricter than yours)

    I tried running your 'exec' line from the command line and got:
    Code:
    $ tst.sh test.txt tmp.txt
    bash: tst.sh: command not found
    I also got the same error when running the php:
    Code:
    $php testcopy.php
    Hello just to check that I am Here
    bash: tst.sh: command not found
    That was it I wonder what the result is?
    I'm not sure why you aren't getting any error messages, but this makes sense to me. As your probably aware, the default path on most (all, except dos/windows, as far as I've seen) shells doesn't include '.'
    So you'll probably need to change the exec line to `./tst.sh ...` or put the shell script somewhere that is in your path.

    Apart from that your code works for me. But I would also suggest adding a shebang to the start of your shell script (#!/bin/sh)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •