1:1 call PHP from Python
Question: We're using Splunk (A tool to analyse machine data like log files) and have an
application in PHP. For some data we need to do a call to our application in
php (CLI-based). Unfortunately Splunk only supports Python calls.  
Is there an easy way to 1:1 "forward/call" php with the same arguments and
return the output, like a "passthru". I've found only parts of the solution
with the socalled subprocess module but my python experience is zero, so can't
get it to work.

For example, splunk calls:  
`python external_lookup.py argument1 argument2 argument3`  
\- Then the python script should call (with the CLI arguments given to
python):  
`php external_lookup.php argument1 argument2 argument3`  
\- Then php writes its output  
\- Python captures that output and outputs it itself

Any help much appreciated, or a working example script even better.

Thanks in advance,  
Vince


Answer: Using `Popen` from the subprocess module:

    
    
    import sys
    from subprocess import Popen
    output = subprocess.Popen(['php', 'path/to/script.php'] + sys.argv[1:], stdout=subprocess.PIPE).communicate()[0]
    

`sys.argv[1:]` contains every command line argument except the name of python
script itself.

