dpswo40440 2015-06-16 18:53
浏览 34
已采纳

在Go中获取PHP配置变量

I want to get the output of the command php -r 'echo get_cfg_var("some_var");' to check it against a predefined value. Currently, I have the following code:

variableName := "default_mimetype"
cmd := exec.Command("php", "-r", "'echo get_cfg_var(\"" + variableName + "\");'")
out, err := cmd.CombinedOutput()

after running,

err.Error() returns "exit status 254"

out is "PHP Parse error: syntax error, unexpected end of file in Command line code on line 1"

What is causing this error? Am I not escaping something properly?

  • 写回答

1条回答 默认 最新

  • drrc61668568 2015-06-16 19:25
    关注

    The problem is your argument. If you change what you have written into a shell command, it would look like the following:

    $ php -r "'echo get_cfg_var(\"default_mimetype\");'"
    

    You will notice that there is an extra set of quotes around the 2nd argument that is causing the syntax error. You can fix this by changing your exec.Command to the following:

    cmd := exec.Command("php", "-r", "echo get_cfg_var(\"" + variableName + "\");")
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 Windows Server 2016利用兩張網卡處理兩個不同網絡
  • ¥15 Python中knn问题
  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源