PHP Shell Command

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anon538
    New Member
    • Sep 2007
    • 23

    PHP Shell Command

    I am attempting to compile and run a simple java file on my server, but I'm not getting any results. Here is what I'm trying to do:
    Code:
    <?php
    echo shell_exec("java/bin/javac Anon.java");
    ?>
    Java is installed in a folder named java.
    Anon.java is in the root directory along with this php file.
    When I run the code, nothing happens. No error messages, no compiled files, nothing.
    I am using Linux (GNU bash, version 2.05b.0(1)-release (i386-redhat-linux-gnu)) on the server.
    Can anyone shed light on how to make this work?
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    Originally posted by anon538
    I am attempting to compile and run a simple java file on my server, but I'm not getting any results. Here is what I'm trying to do:
    Code:
    <?php
    echo shell_exec("java/bin/javac Anon.java");
    ?>
    Java is installed in a folder named java.
    Anon.java is in the root directory along with this php file.
    When I run the code, nothing happens. No error messages, no compiled files, nothing.
    I am using Linux (GNU bash, version 2.05b.0(1)-release (i386-redhat-linux-gnu)) on the server.
    Can anyone shed light on how to make this work?
    Not to answer your question with another question, but have you run the command on the command line and ensured that it actually does output something?

    If it does, then I would suggest a change in your code to store the value in a variable first, as such:

    Code:
    <?php
    $return_value = shell_exec("java/bin/javac Anon.java");
    
    echo "$return_value";
    ?>
    Regards,

    Jeff

    Comment

    • anon538
      New Member
      • Sep 2007
      • 23

      #3
      Unfortunately.. .

      I can't access the command line directly. I am using a shared server, and that is one of the restrictions that my host puts on me. I was just hoping that someone would see something syntactically wrong about my code before I have to go through tech support.

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Originally posted by anon538
        I can't access the command line directly. I am using a shared server, and that is one of the restrictions that my host puts on me. I was just hoping that someone would see something syntactically wrong about my code before I have to go through tech support.
        Have you tried it on a local development server?

        Comment

        • anon538
          New Member
          • Sep 2007
          • 23

          #5
          Fixed

          I appreciate the help, but I figured out the problem after playing around with it for a while. I was using the wrong command.
          Thanks anyway,
          anon

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            Originally posted by anon538
            I appreciate the help, but I figured out the problem after playing around with it for a while. I was using the wrong command.
            Thanks anyway,
            anon
            Could you share your solution, for others with the same problem?

            Comment

            Working...