我必须使用python编写一个新文件,该文件在以下系列中被调用:
html-> ajax-> php-> python
示例python文件:
import subprocess
import os
DIR="/home/name/name1/XML_OUTPUT/try1";
TEMP_VSWITCH_XML = "/home/name/name1/vswitch.xml"
SWITCH_XML = "%s/switch.xml" %DIR
SWITCH_NAME="test_switch";
SCHEMA_VERSION="V1";
def prep_xml():
print "Switch with name %s does not exist, creating SWITCH\n" %SWITCH_NAME;
print "Hello1";
print "Hello2";
os.system("/home/name/name1/XML_OUTPUT/try1/switch.xml");
subprocess.call(" sed \"s/SWITCH_NAME/%s/g\" /home/name/name1/XML/vswitch.xml > %s" %(SWITCH_NAME, TEMP_VSWITCH_XML), shell=True)
print "Got it";
prep_xml();
上面的python脚本由ajax-> php调用。当调用python脚本的php文件名(php -f test.php)时,将生成并修改新文件。但是,当ajax调用php脚本时,什么都行不通。
示例php文件:
<?php
myfunction();
function myfunction()
{
$command=escapeshellcmd('/usr/bin/python sea1.py $2>&1');
$out=shell_exec($command);
echo $out;
}
?>
请帮助我。