SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,397
    Mentioned
    81 Post(s)
    Tagged
    3 Thread(s)

    Can I get variables from a shell script into php variables.

    I am helpng somebody run a shell script from php and he needs to get the variables created in the script back into the php code when the shell script is finished.

    I have suggested he creates the variables in php and send those to the shell script instead; he could do this but would prefer to use the shell script if possible.

    This is the code I am using to call the shell script:
    PHP Code:
    $font "Helvetica-Bold";
    $pointsize "50";
    $textcolor "red";
    $undercolor "blue";
    $bordercolor "yellow";
    $angle "30";
    $resize "100";

    // Run the script
    exec("/home/user/public_html/fred -f $font -p $pointsize -t $textcolor -u $undercolor -b $bordercolor -a $angle -r $resize fred.png 2>&1"$array); 
    //Display any errors
    echo "<br><pre>".print_r($array)."<br>"
    echo 
    "</pre>"

  2. #2
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    348
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, exec() returns the last line of the output from the shell command, so if the shell script is returning output like "value" or "a, b, c" you can capture this output in a var or array as needed.

  3. #3
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    348
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry, I just saw you're outputting a png - look into passthru() if you want to output an image to the browser (binary stream).

  4. #4
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,397
    Mentioned
    81 Post(s)
    Tagged
    3 Thread(s)
    Thats something to think about old_iron and I will do some tests.

    I should have put some more info in my post - the image is a CAPTCA image and the characters are generated in the shell script. He needs the characters generated to check against in the form.
    The shell script is being written so it can be used by different software.

    I have suggested he has the image in the memory only and not save it. The code he has written at the moment has everything hard coded as a test.

    I still think the way to go is get php ( or whatever other software ) to generate the random characters and then send them to the shell script.

  5. #5
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how about this

    test.sh
    Code:
    #!/bin/sh
    
    re=x
    echo $re
    export re
    and the php
    PHP Code:
    <?php

    function render()
    {
        
    $cmd "sh test.sh";

        
    system($cmd);

        echo 
    getenv("re");
    }

    render();
    my mobile portal
    ghiris.ro

  6. #6
    SitePoint Addict
    Join Date
    Oct 2008
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HOw about shell_exec() http://fi.php.net/shell_exec ?

  7. #7
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,397
    Mentioned
    81 Post(s)
    Tagged
    3 Thread(s)
    Thanks for the replys; I have not tried shell_exec() yet and we are trying to think of another way to solve the problem - lateral thinking !

    Ernie1 - I only get one x displayed and that is coming from the shell script; if I comment out echo $re I get nothing displayed.
    I would assume I should have xx One x from the shell script and the other from the php code ?

  8. #8
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,397
    Mentioned
    81 Post(s)
    Tagged
    3 Thread(s)
    I do not get an output from shell_exec() either; I wonder if its a server setup problem.

  9. #9
    SitePoint Addict
    Join Date
    Oct 2008
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you are using some hosting company to host your pages then I think shell_exec and maybe some others also can be forbidden. If you are running own server then it might be some settings also. I dont know more about these settings... I just know some hosting companies disables these.

  10. #10
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can write to a file then read from that file
    Code:
    #!/bin/sh
    
    re=x
    echo $re > test
    my mobile portal
    ghiris.ro

  11. #11
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,397
    Mentioned
    81 Post(s)
    Tagged
    3 Thread(s)
    That works Ernie1; I end up with a file called test containing x

    I will pass on the info and see how it goes


Bookmarks

Posting Permissions

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