【发布时间】:2019-05-08 02:35:41
【问题描述】:
我有可以使用 ReadExisting() 获取数据的 Powershell 语法,但问题是...该语法必须在之前强制 php 条件(以及页面加载时的一些 shell_exec 语法)
我尝试使用 powershell 获取 COM1 数据,并使用此代码
在该图像中,第一个 ReadExisting() 无法声明输出,因为 COM1 中的设备未显示新结果,当设备显示结果时,再次尝试 ReadExisting(),我得到了我想要的。
所以(在我看来)我应该在 PHP 上实现的逻辑是: - 先执行 $port 和 $port.Open() - 之后执行 ReadExisting()。
我正在尝试制作这样的 php 代码
<?php
$result = shell_exec('powershell $port = New-Object System.IO.Ports.SerialPort COM1,9600,None,8,one ; Get-Variable ; $port.Open(); $port.ReadExisting() ');
echo $result
?>
<form method="post">
<input type="submit" name="test" id="test" value="RUN" /><br/>
</form>
<?php
function testfun()
{
$result2 = shell_exec('powershell $port.ReadExisting()');
echo $result2;
}
if(array_key_exists('test',$_POST)){
testfun();
}
?>
但是按钮没有在 powershell 中显示结果。我可能看到了什么,因为我正在制作两个 shell_exec?,是的,$result 正在工作(我已经在测试它,我可以看到端口连接变量)
是否有可能使用按钮条件制作 continue shell 命令的方法?谢谢你!。
【问题讨论】:
标签: php shell-exec