Execute extneral programs with interactivity?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • weberjacob@gmail.com

    Execute extneral programs with interactivity?

    I'm using PHP in command-line mode. I would like to run an external
    command, and have it interact with the user just as if he had ran it
    from a shell. (I don't need my script to send input to the command).
    Ideally I would also like to capture the STDOUT into a variable,
    although this is not a requirement.

    None of the PHP program-execution commands seem to work for me. The
    closest I've come is:
    system("ftp")
    which takes user input, but it seems to buffer the output until you
    type something other than a carriage return. I want it to behave
    exactly as it does from a shell. Is this possible?

    Thanks,
    Jacob

  • Mike Willbanks

    #2
    Re: Execute extneral programs with interactivity?

    weberjacob@gmai l.com wrote:[color=blue]
    > I'm using PHP in command-line mode. I would like to run an external
    > command, and have it interact with the user just as if he had ran it
    > from a shell. (I don't need my script to send input to the command).
    > Ideally I would also like to capture the STDOUT into a variable,
    > although this is not a requirement.
    >
    > None of the PHP program-execution commands seem to work for me. The
    > closest I've come is:
    > system("ftp")
    > which takes user input, but it seems to buffer the output until you
    > type something other than a carriage return. I want it to behave
    > exactly as it does from a shell. Is this possible?
    >
    > Thanks,
    > Jacob
    >[/color]
    Take a look at proc_open.

    Execute a command and open file pointers for input/output



    --
    Mike Willbanks
    Zend Certified Engineer

    Comment

    • weberjacob@gmail.com

      #3
      Re: Execute extneral programs with interactivity?

      I looked at that ... after checking out some of the examples, I was
      able to make it do basically the same thing that system() or popen()
      was doing. It still doesn't seem to handle user input normally.

      I guess I need to send the stdin (from the PHP script) to the stdin of
      the process that I open. But how do I do that?

      Thanks,
      Jacob

      Comment

      • Colin McKinnon

        #4
        Re: Execute extneral programs with interactivity?

        weberjacob@gmai l.com wrote:
        [color=blue]
        > I looked at that ... after checking out some of the examples, I was
        > able to make it do basically the same thing that system() or popen()
        > was doing. It still doesn't seem to handle user input normally.
        >
        > I guess I need to send the stdin (from the PHP script) to the stdin of
        > the process that I open. But how do I do that?
        >
        > Thanks,
        > Jacob[/color]

        On Microsoft/Linux/Unix with a recent PHP:

        $inh=fopen("std in://", 'r');

        With Linux/some Unix:
        $inh=fopen("/dev/stdin", 'r');

        C.

        Comment

        Working...