1:1 call PHP from Python

前端 未结 2 939
悲&欢浪女
悲&欢浪女 2021-01-28 06:26

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). Unf

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-28 06:52

    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.

提交回复
热议问题