首页 \ 问答 \ 当PHP中的shell_exec()执行脚本时,Python open()函数不起作用(Python open() function not working when script executed by shell_exec() in PHP)

当PHP中的shell_exec()执行脚本时,Python open()函数不起作用(Python open() function not working when script executed by shell_exec() in PHP)

我的Python脚本中有一个open()命令,它在w模式下运行在Raspberry Pi上的Apache服务器中打开文件data.json 。 反过来,这个脚本由PHP使用shell_exec命令运行。 当脚本单独运行时,Python代码可以正常工作。 但是,它在PHP运行时不起作用。 有谁知道为什么会这样,或者需要更多信息? 预先感谢您的帮助!


I have a open() command in my Python script which opens the file data.json in my Apache serve running on Raspberry Pi in w mode. This script in turn is run by PHP using the shell_exec command. When the script is run alone, the Python code works. However, it does not function when run by PHP. Does anyone have any idea why this is happening, or is more information needed? Thank you in advance for your help!


原文:https://stackoverflow.com/questions/47463593
更新时间:2023-02-16 17:02

最满意答案

不会。 $class会有一个false值,但如果你想让方法终止并立即返回该值,你仍然需要从YourClass::a()返回它。 return仅在其调用的函数/方法的范围内。

public static function a(){ 
  $class = getClass();
  if (!$class) {
      return false; // or return $class;
  }
  some more code...
}

No. $class will have a false value but you still need to return it from YourClass::a() if you want the method to terminate and return that value immediately. return only is in scope of the function/method it is called from.

public static function a(){ 
  $class = getClass();
  if (!$class) {
      return false; // or return $class;
  }
  some more code...
}

相关问答

更多
  • 就像Raveren说的那样,你不能发送整数或布尔值到PHP。 所有发送的数据始终是字符串。 如果你仍然想使用if($ post)而不是if($ post =='true'),那么使用switch switch($post) { case "true": $post = true; break; case "false": $post = false; break; } if ($post) { ... } 没有其他办 ...
  • 变量赋值返回您赋给变量的值。 因此,当strpos调用返回false (当找不到$needle时),赋值也将如此,循环将终止。 A variable assignment returns the value you assigned to the variable. So when the strpos call returns false (when the $needle isn't found), so will the assignment, and the loop will terminate. ...
  • 构造函数始终返回类的新实例 。 您不能从构造函数返回任何其他类型的值。 构建代码的更好方法是: source: signup.php class Signup { public $success; protected function buildProfile() { if($logic){ $this->success = true; }else{ $this->success = false; ...
  • 您的功能中没有$con 。 替换此行: if (user_exists('tijmen') === true) { 通过: if (user_exists('tijmen',$con) === true) { 在你的功能: function user_exists($username,$con) { $query = mysqli_query($con, "SELECT COUNT(*) FROM users WHERE username='$username'") or die (mysqli_err ...
  • 在PHP中,当转换为一个字符串时为false是一个空字符串,并且true转换为一个字符串为“1”。 使用var_dump而不是echo来进行调试。 In PHP, false when converted to a string is an empty string, and true converted to a string is "1". Use var_dump instead of echo for debugging.
  • 不。构造函数没有返回值。 如果你需要从构造函数获得某种结果,你可以做一些事情: 如果您需要返回值,请使用一种方法来完成繁重的工作(通常称为init() )。 public static function init( $host, $username, $password, $connection_type ){ //setting the classes vars $this->host = $host; $this->username = $usernam ...
  • 如果var被设置为除true之外的其他任何值,那么php是否会假? 一点也不。 PHP将返回任何变量设置。 实际上,由于你有一个非空字符串,这是一个“真值”(即:在布尔上下文中为true )。 既然您使用if ($result)作为您的支票,并且您返回一个“真值”值,则条件始终为真。 您需要将该支票更改为: if ($result === true) { ... 处理这个问题的正确方法是什么? 我认为这是一个很好的处理方法。 另一种方法是通过引用传递错误字符串变量,并让代码的失败部分填充,例如: ...
  • 是的,它告诉函数停止执行,并返回值“false”。 所以它做了一些事情。 是否有用取决于您的编程。 如果在echo之后没有可执行行,并且该函数不需要返回值,那么它实际上不会做任何有用的事情。 如果确实让读者更清楚“这是一个停止/失败点”。 有一天你可能想要实际陷阱,如果它工作或失败 - 所以留下它使它更清楚。 您也可以在不考虑的情况下扩展功能,并且需要重新调整返回值 - 再次,将其放入使其更容易。 相反,还有来自C / Assembler日期的旧编程风格,你只有一个入口和一个出口点,所有函数都可以帮助进行垃 ...
  • 工作小提琴 。 在函数调用之前在onclick添加return : 希望这可以帮助。 Working Fiddle. Add return in onclick before function call :

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。