dre93205 2014-01-30 01:48
浏览 47
已采纳

将参数从php传递给python不完整

I'm having a problem on passing the parameters from php to python.

By using the $_SERVER['QUERY_STRING'].

http://www.domain.com/path?a_num=123&msg=hello

i will put the a_num=123&msg=hello to a variable

$a = $_SERVER['QUERY_STRING'];
system("python python.py ".$a);

and in python will print it

a = sys.argv[1]
print a

and the result is *a_num=123* only

what is the problem?

  • 写回答

1条回答 默认 最新

  • dqy0707 2014-01-30 02:45
    关注

    I don't think this is a problem with PHP, more how the system command is being executed. Assuming you are using Linux, the '&' character in the command:

    python python.py a_num=123&msg=hello
    

    Is being interpreted as a control operator. From the documentation for bash (although this applies equally to other shells such as tcsh):

    If a command is terminated by the control operator &, the shell executes the command in the background in a subshell. The shell does not wait for the command to finish, and the return status is 0.

    To prevent this, you need to quote the string being passed:

    python python.py "a_num=123&msg=hello"
    

    Which in PHP would look like:

    system("python python.py \"".$a."\"");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!