Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Aug 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    can't get PHP to exec() an Expect script (.exp)

    Hello all, I have an Expect script written in Tcl that I need PHP to execute. However, I don't think that PHP's exec(), system(), passthru() or shell_exec() executes the Expect script. I tried with other scripts such as Python and shell scripts and PHP executes them fine. For some reason it doesn't even excute the simplest Expect script or Tcl script (such as Hello World). This leads me to believe that PHP isn't capable of exec() Tcl scripts? Is there some module that I have to manually install?

    Thanks for any help!

  • #2
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    are the files executable? do you have permission to execute the scripts?
    try:
    Code:
    echo shell_exec('blahblahblah.tcl 2>&1');

  • #3
    New Coder
    Join Date
    Aug 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes I used "chmod 755 *" on all my files. I can run the files at the command line with no problems. I can even use exec() to run other Python and shell scripts. Just not Expect scripts or Tcl scripts. I'm stumped.

  • #4
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    when you run the script from the command line, do you type
    ./scriptname
    or do you have to use
    tcl scriptname
    or
    exp scriptname
    or something similar?

    If this is the case, then you either need to include that in the exec, or place a 'shebang' at the top of the script, before everything else:
    Code:
    #!/usr/bin/tcl
    //script starts
    If you don't get this sorted, perhaps post a simple example of such a script (I've heard of tcl, but that's as far as it goes...!), might have time to play around later...

  • #5
    New Coder
    Join Date
    Aug 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by GJay
    when you run the script from the command line, do you type
    ./scriptname
    or do you have to use
    tcl scriptname
    or
    exp scriptname
    or something similar?

    If this is the case, then you either need to include that in the exec, or place a 'shebang' at the top of the script, before everything else:
    Code:
    #!/usr/bin/tcl
    //script starts
    If you don't get this sorted, perhaps post a simple example of such a script (I've heard of tcl, but that's as far as it goes...!), might have time to play around later...
    Hi GJay, I added the #! (shebang ahahaha) at the top of the script before so that I could execute it without the tcl/expect commands explicitly. I have to put the "./" in the exec() to make the python and shell scripts work. I will try adding the tcl/expect in the exec() anyway to see if it'll work.

    Thanks!

  • #6
    New Coder
    Join Date
    Aug 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey problem solved, as it turns out i needed to do

    Code:
    exec("expect blah.exp");
    instead of

    Code:
    exec("blah.exp");
    Now I have another problem, but I think it might be a permission access problem. The script that I run has to move a file from /tftpboot directory into my home directory. When I run the script in command line, it moves the file fine. However, when I run the same script using PHP, it doesn't move the file. The file is actually in /tftpboot directory but it doesnt get moved into my home. Is this because Apache doesn't have access to /tftpboot?

    Thx!

  • #7
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    run this and it will tell you the error
    Code:
    echo shell_exec('your_script.sh 2>&1');
    it probably is a permission error.

  • #8
    New Coder
    Join Date
    Aug 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey fci, thx for the help. It is a permission problem I'll have to talk to the server admin about this. Just curious, what does the 2>&1 do in that?

  • #9
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    redirects stderr to stdout.


  •  

    Posting Permissions

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